Rust
Rust
Get Filenames in a Remote Directory
Gets the names of files in a remote FTP directory.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("myLogin");
ftp.set_password("myPassword");
// Use explicit TLS
ftp.set_auth_tls(true);
ftp.set_port(21);
// Connect and login to the FTP server.
if ftp.connect().is_err() {
println!("{}", ftp.last_error_text());
return;
}
// Iterate over .txt files.
ftp.set_list_pattern("*.txt");
let n = ftp.get_dir_count();
println!("n = {}", n);
let mut i = 0;
while i < n {
println!("{}: {}", i, ftp.get_filename(i).unwrap_or_default());
i = i + 1;
}