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

Async PUT from stream #12

Open
mihaigalos opened this issue Nov 30, 2021 · 2 comments
Open

Async PUT from stream #12

mihaigalos opened this issue Nov 30, 2021 · 2 comments

Comments

@mihaigalos
Copy link
Contributor

mihaigalos commented Nov 30, 2021

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.
@mihaigalos
Copy link
Contributor Author

Not sure if possible, but of potential interest: usage of async_stream::stream! for https PUT.

@mihaigalos
Copy link
Contributor Author

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

1 participant