Sample code for 30+ languages & platforms
Rust

Connect to FTP Through an HTTP Proxy

See more FTP Examples

Demonstrates connecting through an HTTP proxy using HttpProxyHostname, HttpProxyPort, HttpProxyUsername, HttpProxyPassword, HttpProxyAuthMethod, and HttpProxyDomain.

Background: Many corporate networks force outbound traffic through an HTTP proxy, which reaches the FTP control connection via the CONNECT method — so the proxy must permit CONNECT to the FTP port. HttpProxyAuthMethod is Basic or NTLM, with HttpProxyDomain supplying the Windows domain for NTLM. This is distinct from a traditional FTP proxy, which speaks FTP itself.

Chilkat Rust Downloads

Rust

let ftp = chilkat::Ftp2::new();

ftp.set_hostname("ftp.example.com");
ftp.set_username("myFtpLogin");

// The HTTP proxy through which the FTP control connection is made.  Common ports are 8080 and
// 3128.
ftp.set_http_proxy_hostname("proxy.example.com");
ftp.set_http_proxy_port(8080);

// Proxy authentication, if required.  HttpProxyAuthMethod is "Basic" or "NTLM"; HttpProxyDomain
// is the Windows domain used for NTLM.
ftp.set_http_proxy_username("myProxyLogin");
ftp.set_http_proxy_password("myProxyPassword");
ftp.set_http_proxy_auth_method("NTLM");
ftp.set_http_proxy_domain("CORP");

// Normally you would not hard-code the password in source.  You should instead obtain it
// from an interactive prompt, environment variable, or a secrets vault.
ftp.set_password("myPassword");

if ftp.connect().is_err() {
    println!("{}", ftp.last_error_text());
    return;
}

println!("Connected through the HTTP proxy.");

if ftp.disconnect().is_err() {
    println!("{}", ftp.last_error_text());
    return;
}