I'm trying to use a loop to read data from a file, PUT it to a FTP server and update a progress bar.
tokio::fs::File already implements the R trait trait in put:
pub async fn put<R: AsyncRead + Unpin>(&mut self, filename: &str, r: &mut R) -> Result<()>
So one can just write something like:
let mut file = tokio::fs::File::open(&filename).await.unwrap();
let mut ftp_stream = FtpStream::connect(server_address);
ftp_stream.put(filename, &mut file).await.unwrap();
Qs:
- how do I instead use a
loop to buffer-read from the file and async PUT it to the ftp stream?
- why does the
r in the put signature need to be mutable? I'm kind of confused, since we just read from the file. I see here, r is just copied.
I'm trying to use a loop to read data from a file,
PUTit to a FTP server and update a progress bar.tokio::fs::Filealready implements the R trait trait input:So one can just write something like:
Qs:
loopto buffer-read from the file and async PUT it to the ftp stream?rin theputsignature need to be mutable? I'm kind of confused, since we just read from the file. I see here,ris just copied.