Rust
Rust
Download Multiple Files Matching Pattern
See more FTP Examples
The MGetFiles method can be called to download all files matching a wildcarded filename pattern.Chilkat Rust Downloads
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
let ftp = chilkat::Ftp2::new();
ftp.set_hostname("ftp.example.com");
ftp.set_username("myUsername");
ftp.set_password("myPassword");
ftp.set_port(21);
ftp.set_auth_tls(true);
// Connect and login to the FTP server.
if ftp.connect().is_err() {
println!("{}", ftp.last_error_text());
return;
}
// Change to the remote directory where the files are located.
// This step is only necessary if the files are not in the root directory
// of the FTP account.
if ftp.change_remote_dir("qa").is_err() {
println!("{}", ftp.last_error_text());
return;
}
// Download all files with filenames matching "*.txt";
// The files are downloaded into c:/temp/qa_output
let num_files_downloaded = ftp.m_get_files("*.txt", "c:/temp/qa_output");
if num_files_downloaded < 0 {
println!("{}", ftp.last_error_text());
return;
}
let _ = ftp.disconnect().is_ok();
println!("{} Files Downloaded!", num_files_downloaded);