Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ERROR - Disconnected #49

Open
TheMuteM opened this issue Sep 9, 2024 · 1 comment
Open

ERROR - Disconnected #49

TheMuteM opened this issue Sep 9, 2024 · 1 comment

Comments

@TheMuteM
Copy link

TheMuteM commented Sep 9, 2024

When I am on a server with high latency, it is normal to call upd_content at the beginning. But after a few minutes, ERROR - Disconnected will appear when calling

pub async fn create_sftp_session(session: &Session) -> Result<SftpSession> {
    let sftp_channel = session.channel_open_session().await?;
    sftp_channel.request_subsystem(true, "sftp").await?;
    let session1 = SftpSession::new(sftp_channel.into_stream()).await?;
    session1.set_timeout(2000).await;
    Ok(session1)
}


    pub async fn upd_content(&self, file_path: String, content: String) -> Result<()> {
        info!("upd_content file_path:{}",file_path);
        let guard = self.ssh_session.lock().await;
        let session = guard.as_ref().unwrap();
        let sftp_channel = create_sftp_session(&session).await?;

        let mut remote_file = sftp_channel.open_with_flags(file_path, OpenFlags::CREATE | OpenFlags::TRUNCATE | OpenFlags::WRITE).await?;
        // file.write_all(content.as_ref()).await?;
        // let mut remote_file = sftp_channel.create(&remote_path).await?;

        const CHUNK_SIZE: usize = 5120; 
        let mut pos = 0;
        let content_bytes = content.as_bytes();
        while pos < content_bytes.len() {
            let end = std::cmp::min(pos + CHUNK_SIZE, content_bytes.len());
            remote_file.write_all(&content_bytes[pos..end]).await?;
            pos = end;
        }
        remote_file.shutdown().await?;
        sftp_channel.close().await?;
        Ok(())
    }

Config

   let mut config = client::Config {
        inactivity_timeout: Some(Duration::from_secs(20000)),
        keepalive_interval: Some(Duration::from_secs(5000)),
        keepalive_max: 6,
        ..<_>::default()
    };
@AspectUnk
Copy link
Owner

AspectUnk commented Sep 27, 2024

Please attach full debug logs and/or a working example out of the box

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants