Sample code for 30+ languages & platforms
Rust

FTPS with Mutual TLS Authentication (TLS Client Certificate)

See more FTP Examples

Demonstrates how to do mutual TLS authentication (using a client certificate from a .pfx/.p12).

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_port(21);

// If using implicit TLS, you probably want port 990..
ftp.set_port(990);

// Set this to false for implicit TLS, otherwise set to true for explicit TLS (where port is typically 21).
ftp.set_auth_tls(false);

// Set this to true for implicit TLS, otherwise set to false.
ftp.set_ssl(true);

let cert = chilkat::Cert::new();
if cert.load_pfx_file("qa_data/pfx/example.pfx", "pfx_password").is_err() {
    println!("{}", cert.last_error_text());
    return;
}

// Use this certificate for our TLS mutually authenticated connection:
if ftp.set_ssl_client_cert(&cert).is_err() {
    println!("{}", cert.last_error_text());
    return;
}

// Establish the TLS connection with the FTP server.
if ftp.connect_only().is_err() {
    println!("{}", ftp.last_error_text());
    return;
}

// If a login is required, then login with the FTP account login/password.
ftp.set_username("myLogin");
ftp.set_password("myPassword");
if ftp.login_after_connect_only().is_err() {
    println!("{}", ftp.last_error_text());
    return;
}

// Do whatever you're doing to do ...
// upload files, download files, etc...

// .....
// .....

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