Open
Description
I'm currently trying to use this crate in a small project for the purpose of downloading a file via sftp.
I don't know if I'm missing something, but with my naive implementation, downloading the file is several times slower than with the standard sftp client. What I'm doing is this:
use bytes::{BytesMut};
use openssh::{KnownHosts, Session, Stdio};
use openssh_sftp_client::Sftp;
use std::error::Error;
use std::fs::File;
use std::io::Write;
#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
let session = Session::connect_mux(
"ssh://user@host",
KnownHosts::Accept,
)
.await?;
let mut child = session
.subsystem("sftp")
.stdin(Stdio::piped())
.stdout(Stdio::piped())
.spawn()
.await?;
let sftp_client = Sftp::new(
child.stdin().take().unwrap(),
child.stdout().take().unwrap(),
Default::default(),
)
.await?;
let mut zip_file = sftp_client
.options()
.read(true)
.open("myfile")
.await?;
let mut tmp_file = File::create("myfile").unwrap();
let buf_size = 100 * 1024 * 1024;
while let Ok(read_result) = zip_file
.read(
buf_size,
BytesMut::with_capacity(buf_size.try_into().unwrap()),
)
.await
{
if let Some(data) = read_result {
tmp_file.write_all(&data)?;
} else {
break;
}
}
Ok(())
}
Any hints are appreciated.
Metadata
Metadata
Assignees
Labels
No labels