suppaftp icon indicating copy to clipboard operation
suppaftp copied to clipboard

Question: example function utilizing retr

Open tadghh opened this issue 8 months ago • 2 comments

I'm trying to download a single file using the retr function, but I can't seem to grasp the reader: F part. I attempted to get ChatGPT to explain but that resulted in "dyn async_std::io::Read cannot be unpinned".

Here is what I have so far, it contains the issue mentioned


pub async fn download_file2(file_name: String) -> Result<(), suppaftp::FtpError> {
    //NOTE need to include port
    let mut ftp_stream = AsyncFtpStream::connect("127.0.0.1:21").await?;

    ftp_stream.login("user", "pass").await.expect("no login");

    //TODO env for this path, it also needs to prefix with /public
    ftp_stream.cwd("/path/to/images").await?;

    match ftp_stream
        .retr(file_name, |stream| {
            let mut buffer = Vec::new();
            // Cannot be unpinned
            stream.read_vectored(&mut buffer);
            Ok(buffer)
        })
        .await
    {
        Ok(data) => {
            // Write the file to the local file system
            eprintln!("shush");
        }
        Err(e) => {
            eprintln!("Failed to retrieve file: {}", e);
        }
    }
    // Logout and quit the session
    ftp_stream.quit().await?;
    Ok(())
}

I'm still learning so perhaps im missing something silly. Thanks in advance.

tadghh avatar May 27 '24 07:05 tadghh