Rust
Rust
SCP Download File
See more SCP Examples
Demonstrates how to download a file using the SCP protocol (Secure Copy Protocol over SSH).Chilkat Rust Downloads
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
let ssh = chilkat::Ssh::new();
// Hostname may be an IP address or hostname:
let hostname = "www.some-ssh-server.com".to_string();
let port = 22;
// Connect to an SSH server:
if ssh.connect(&hostname, port).is_err() {
println!("{}", ssh.last_error_text());
return;
}
// Wait a max of 5 seconds when reading responses..
ssh.set_idle_timeout_ms(5000);
// Authenticate using login/password:
if ssh.authenticate_pw("myLogin", "myPassword").is_err() {
println!("{}", ssh.last_error_text());
return;
}
// Once the SSH object is connected and authenticated, we use it
// in our SCP object.
let scp = chilkat::Scp::new();
if scp.use_ssh(&ssh).is_err() {
println!("{}", scp.last_error_text());
return;
}
let remote_path = "test.txt".to_string();
let local_path = "/home/bob/test.txt".to_string();
if scp.download_file(&remote_path, &local_path).is_err() {
println!("{}", scp.last_error_text());
return;
}
println!("SCP download file success.");
// Disconnect
ssh.disconnect();