Skip to content

Async PUT from stream #12

Description

@mihaigalos

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions