Rust
Rust
SFTP Upload and Download to a BinData Object
See more SFTP Examples
Demonstrates how to SFTP upload from a BinData object, and download into a BinData object.Chilkat Rust Downloads
let mut success = false;
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
let sftp = chilkat::SFtp::new();
// Set some timeouts, in milliseconds:
sftp.set_connect_timeout_ms(5000);
sftp.set_idle_timeout_ms(10000);
// Connect to the SSH server and then authenticate.
let port = 22;
success = sftp.connect("MY-SSH-SERVER-DOMAIN-OR-IP", port).is_ok();
if success {
success = sftp.authenticate_pw("MY-SSH-LOGIN", "MY-SSH-PASSWORD").is_ok();
if success {
success = sftp.initialize_sftp().is_ok();
}
}
if !success {
println!("{}", sftp.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 SSH/SFTP server.
let remote_path = "sftpTesting/penguins.jpg".to_string();
if sftp.upload_bd(&bd_a, &remote_path).is_err() {
println!("{}", sftp.last_error_text());
return;
}
// Download the file..
let bd_b = chilkat::BinData::new();
if sftp.download_bd(&remote_path, &bd_b).is_err() {
println!("{}", sftp.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.");
}
sftp.disconnect();