Rust
Rust
SFTP Download Files Matching a Pattern
See more SFTP Examples
Demonstrates how to download files in a directory matching one or more patterns (such as "*.zip" or "abc*_*0719.csv".Chilkat Rust Downloads
let mut success = false;
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
let sftp = chilkat::SFtp::new();
success = sftp.connect("my-ssh-server.com", 22).is_ok();
if success {
success = sftp.authenticate_pw("mySshLogin", "mySshPassword").is_ok();
}
if success {
success = sftp.initialize_sftp().is_ok();
}
if !success {
println!("{}", sftp.last_error_text());
return;
}
// The SyncTreeDownload method can be used non-recursively to download all files matching a set of patterns.
// This example will download all files, but only those files having filenames
// that match *.csv and *.eml
sftp.set_sync_must_match("*.eml; *.gif");
let remote_dir = "syncDownloadTest/someDir".to_string();
let local_dir = "qa_output".to_string();
// mode=0: Download all matching files according to SyncMustMatch
let mode = 0;
// do not recursively traverse the remote directory tree.
let recursive = false;
if sftp.sync_tree_download(&remote_dir, &local_dir, mode, recursive).is_err() {
println!("{}", sftp.last_error_text());
return;
}
println!("Success.");