Sample code for 30+ languages & platforms
Rust Requires Chilkat v11.0.0+

FTP Connect, Examine Server Certificate, and then Authenticate

See more FTP Examples

Demonstrates how to connect to an FTP server, examine the server's SSL/TLS certificate, and then, if it meets the application's security requirements, proceed to authenticate.

Chilkat Rust Downloads

Rust

// This example assumes Chilkat Ftp2 to have been previously unlocked.
// See Unlock Ftp2 for sample code.

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

ftp.set_hostname("www.authtls-ftps-server.com");
ftp.set_username("FTP_LOGIN");
ftp.set_password("FTP_PASSWORD");
ftp.set_auth_tls(true);
ftp.set_port(21);

// Connect to the FTP server using explicit TLS (AUTH TLS).
if ftp.connect_only().is_err() {
    println!("{}", ftp.last_error_text());
    return;
}

// Get the FTP server's certificate.
let server_cert = chilkat::Cert::new();
if ftp.get_server_cert(&server_cert).is_err() {
    println!("{}", ftp.last_error_text());
    return;
}

// Now that we have the certificate, we can check it in any way we desire.
// (See the online reference documentation for the certificate object's methods
// and properties)...

// Assuming the certificate is OK, proceed to authenticate with the FTP server.
if ftp.login_after_connect_only().is_err() {
    println!("{}", ftp.last_error_text());
    return;
}

// Proceed with uploading/download files, etc...
// 

let _ = ftp.disconnect();
println!("Success.");