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

Downloading multiple files using a single SFTP session #15

Open
zidaye opened this issue Dec 14, 2023 · 0 comments
Open

Downloading multiple files using a single SFTP session #15

zidaye opened this issue Dec 14, 2023 · 0 comments

Comments

@zidaye
Copy link
Contributor

zidaye commented Dec 14, 2023

Similar to #14 , uploading multiple files in a single session significantly improves performance. I want to try downloading multiple files in a single session, but what perplexes me is that it gets blocked during the response reading process until it times out

async fn test_upload_data(mut sftp: SftpSession, file_count: i32, file_size: i32) {
    let mut handler_vec = Vec::new();
    let start_time = Instant::now();
    let dir = sftp.read_dir("data-sync").await.unwrap();
    for dir_file in dir {
        let path = format!("data-sync/{}", dir_file.file_name());
        let mut file = sftp.open_with_flags(
            path.clone(),
            OpenFlags::READ,
        )
        .await.unwrap();
        let mut dest = fs_File::create(path.clone()).unwrap();
        let handler = task::spawn(async move {
            let start_time = Instant::now();

            let mut buffer = Vec::new();
     
            file.read_to_end(&mut buffer).await.unwrap();

            let elapsed_time = start_time.elapsed();
            println!("read_all Time elapsed: {:?}", elapsed_time);
            dest.write_all(&buffer).unwrap();
            let elapsed_time = start_time.elapsed();
            println!("writr_all Time elapsed: {:?}", elapsed_time);

        });
        handler_vec.push(handler);
    }

    futures::future::join_all(handler_vec).await;
    let elapsed_time = start_time.elapsed();
    println!("Time elapsed: {:?}", elapsed_time);
 
}

Does anyone have any insights into this?

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