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(())
}
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
Config