Rust
Rust
Upgrade an FTP Control Channel to TLS (ConvertToTls)
See more FTP Examples
Demonstrates the Chilkat Ftp2.ConvertToTls method, which upgrades an already-connected clear FTP control channel to explicit TLS. It takes no arguments and is used with a manually staged connection created by ConnectOnly while Ssl is disabled.
Background: This exposes the explicit-FTPS
AUTH TLS upgrade as a discrete step for the rare case where you need to do something on the clear connection first — inspect the greeting, apply a workaround — before securing it. In the normal case you simply set AuthTls and let Connect perform the upgrade automatically; this manual path exists for staged control.Chilkat Rust Downloads
// Demonstrates the Ftp2.ConvertToTls method, which upgrades an already-connected clear FTP control
// channel to explicit TLS. It takes no arguments. It is used with a manually staged connection
// created by ConnectOnly while Ssl is disabled.
let ftp = chilkat::Ftp2::new();
ftp.set_hostname("ftp.example.com");
ftp.set_port(21);
// Connect in clear text first (Ssl is false).
if ftp.connect_only().is_err() {
println!("{}", ftp.last_error_text());
return;
}
// Upgrade the control channel to explicit TLS (AUTH TLS).
if ftp.convert_to_tls().is_err() {
println!("{}", ftp.last_error_text());
return;
}
// Now authenticate over the encrypted control channel.
ftp.set_username("myFtpLogin");
ftp.set_password("myPassword");
if ftp.login_after_connect_only().is_err() {
println!("{}", ftp.last_error_text());
return;
}
println!("Control channel upgraded to TLS and logged in.");
if ftp.disconnect().is_err() {
println!("{}", ftp.last_error_text());
return;
}