Rust
Rust
FTP Upload / Download to a BinData Object
Demonstrates how to FTP upload the contents of a BinData object, and FTP downloads to the a BinData object.Chilkat Rust Downloads
// This example assumes Chilkat Ftp2 to have been previously unlocked.
// See Unlock Ftp2 for sample code.
let ftp = chilkat::Ftp2::new();
ftp.set_hostname("www.my-ftp-server.com");
ftp.set_username("mFtpLogin");
ftp.set_password("myFtpPassword");
// Connect to the FTP server.
if ftp.connect_only().is_err() {
println!("{}", ftp.last_error_text());
return;
}
// Authenticate with the FTP server.
if ftp.login_after_connect_only().is_err() {
println!("{}", ftp.last_error_text());
return;
}
let bd_a = chilkat::BinData::new();
let _ = bd_a.load_file("qa_data/jpg/penguins.jpg");
// Upload the contents of bdA to the FTP server.
let remote_filename = "penguins.jpg".to_string();
if ftp.put_file_bd(&bd_a, &remote_filename).is_err() {
println!("{}", ftp.last_error_text());
return;
}
// Download...
let bd_b = chilkat::BinData::new();
if ftp.get_file_bd(&remote_filename, &bd_b).is_err() {
println!("{}", ftp.last_error_text());
return;
}
// Verify that bdA and bdB have the exact same contents.
println!("size of bdA: {}", bd_a.num_bytes());
if bd_a.contents_equal(&bd_b) {
println!("Contents are equal. Success.");
} else {
println!("Contents are NOT equal. Failed.");
}
let _ = ftp.disconnect();