Rust
Rust
FTPS with Client Cert from Windows Certificate Store
See more FTP Examples
Demonstrates how to do mutual TLS authentication using a client certificate installed in the Windows certificate store.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");
// 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_by_common_name("The common name of your certificate").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();