Sample code for 30+ languages & platforms
Rust

FTP through HTTP Tunnel (FTP over HTTP Proxy)

See more FTP Examples

Note: This example requires Chilkat v9.5.0.51 or greater.

FTP through an HTTP tunnel (via an HTTP proxy server that supports HTTP tunneling).

Chilkat Rust Downloads

Rust

// 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");

// Set the HTTP proxy server properties.
// This is to connect via HTTP/1.1 using CONNECT method
ftp.set_http_proxy_hostname("192.168.1.127");
ftp.set_http_proxy_port(8080);

// If the proxy server requires authentication...
ftp.set_http_proxy_username("myProxyUsername");
ftp.set_http_proxy_password("myProxyPassword");

// FTP over an HTTP proxy requires that FTP Passive mode be used
// for data transfers. It is not possible to use non-passive (active) mode
// for FTP over HTTP.
ftp.set_passive(true);

// 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 will be uploaded.
if ftp.change_remote_dir("junk").is_err() {
    println!("{}", ftp.last_error_text());
    return;
}

// Upload a file.
let local_filename = "c:/temp/hamlet.xml".to_string();
let remote_filename = "hamlet.xml".to_string();

if ftp.put_file(&local_filename, &remote_filename).is_err() {
    println!("{}", ftp.last_error_text());
    return;
}

let _ = ftp.disconnect().is_ok();

println!("File Uploaded!");