Rust
Rust
FTP Upload / Download to StringBuilder
Demonstrate how to upload from a Chilkat StringBuilder object, and download into a StringBuilder 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 sb_a = chilkat::StringBuilder::new();
let _ = sb_a.load_file("qa_data/hamlet.xml", "utf-8");
// Upload the contents of sbA to the FTP server.
let b_include_bom = false;
let remote_filename = "hamletFromSb.xml".to_string();
if ftp.put_file_sb(&sb_a, "utf-8", b_include_bom, &remote_filename).is_err() {
println!("{}", ftp.last_error_text());
return;
}
// Download...
let sb_b = chilkat::StringBuilder::new();
if ftp.get_file_sb(&remote_filename, "utf-8", &sb_b).is_err() {
println!("{}", ftp.last_error_text());
return;
}
// Verify that sbA and sbB have the exact same contents.
println!("size of sbA: {}", sb_a.length());
let b_case_sensitive = true;
if sb_a.contents_equal_sb(&sb_b, b_case_sensitive) {
println!("Contents are equal. Success.");
} else {
println!("Contents are NOT equal. Failed.");
}
let _ = ftp.disconnect();