Rust
Rust
FTP Bandwidth Throttle for Downloads
See more FTP Examples
Demonstrates the Chilkat FTP2 download bandwidth throttling property : BandwidthThrottleDown.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("login");
ftp.set_password("password");
// To use FTP bandwidth throttling, set the BandwidthThrottleDown
// property to a maximum desired bytes/second:
// This example limits the download to 50K per second.
ftp.set_bandwidth_throttle_down(50000);
// The default data transfer mode is "Active" as opposed to "Passive".
// 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 file is located.
// This step is only necessary if the file is not in the root directory
// for the FTP account.
if ftp.change_remote_dir("junk").is_err() {
println!("{}", ftp.last_error_text());
return;
}
// Download a file.
let local_filename = "hamlet.xml".to_string();
let remote_filename = "hamlet.xml".to_string();
if ftp.get_file(&remote_filename, &local_filename).is_err() {
println!("{}", ftp.last_error_text());
return;
}
let _ = ftp.disconnect().is_ok();
println!("File Downloaded!");