Rust
Rust
Set an FTP Compatibility Option
See more FTP Examples
Demonstrates the Chilkat Ftp2.SetOption method, which enables or disables a named compatibility option. The only argument is the option name; matching is case-insensitive, and prefixing a recognized name with No- disables it.
Background: Real-world FTP servers have quirks, and these named options are targeted workarounds for specific ones — for example
Microsoft-TLS-1.2-Workaround addresses a known interoperability issue. Most applications never need any of them; reach for SetOption only when a documented server problem calls for a specific fix, and use the exact recognized name.Chilkat Rust Downloads
// Demonstrates the Ftp2.SetOption method, which enables or disables a named compatibility option.
// The only argument is the option name. Prefix a name with "No-" to disable it.
let ftp = chilkat::Ftp2::new();
ftp.set_hostname("ftp.example.com");
ftp.set_username("myFtpLogin");
// 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;
}
// Enable a recognized compatibility workaround. Option-name matching is case-insensitive.
if ftp.set_option("Microsoft-TLS-1.2-Workaround").is_err() {
println!("{}", ftp.last_error_text());
return;
}
// To disable it, prefix the name with "No-":
if ftp.set_option("No-Microsoft-TLS-1.2-Workaround").is_err() {
println!("{}", ftp.last_error_text());
return;
}
println!("Compatibility option toggled.");
if ftp.disconnect().is_err() {
println!("{}", ftp.last_error_text());
return;
}