Rust
Rust
SOCKS4 and SOCKS5 Proxy for FTP
See more FTP Examples
Demonstrates how to connect to an FTP server through a SOCKS4 or SOCKS5 proxy. Both SSL/TLS and non-secure FTP communications may use SOCKS4 and SOCKS5 proxies.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 a SOCKS4 or SOCKS5 proxy, simply set the following
// properties prior to connecting:
// The SOCKS hostname may be a domain name or
// IP address:
ftp.set_socks_hostname("www.mysocksproxyserver.com");
ftp.set_socks_port(1080);
ftp.set_socks_username("myProxyLogin");
ftp.set_socks_password("myProxyPassword");
// Set the SOCKS version to 4 or 5 based on the version
// of the SOCKS proxy server:
ftp.set_socks_version(5);
// Note: SOCKS4 servers only support usernames without passwords.
// SOCKS5 servers support full login/password authentication.
// 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 = "c:/temp/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!");