C
C
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 C Downloads
#include <C_CkFtp2.h>
void ChilkatSample(void)
{
BOOL success;
HCkFtp2 ftp;
success = FALSE;
// 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.
ftp = CkFtp2_Create();
CkFtp2_putHostname(ftp,"ftp.example.com");
CkFtp2_putUsername(ftp,"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.
CkFtp2_putPassword(ftp,"myPassword");
success = CkFtp2_Connect(ftp);
if (success == FALSE) {
printf("%s\n",CkFtp2_lastErrorText(ftp));
CkFtp2_Dispose(ftp);
return;
}
// Enable a recognized compatibility workaround. Option-name matching is case-insensitive.
success = CkFtp2_SetOption(ftp,"Microsoft-TLS-1.2-Workaround");
if (success == FALSE) {
printf("%s\n",CkFtp2_lastErrorText(ftp));
CkFtp2_Dispose(ftp);
return;
}
// To disable it, prefix the name with "No-":
success = CkFtp2_SetOption(ftp,"No-Microsoft-TLS-1.2-Workaround");
if (success == FALSE) {
printf("%s\n",CkFtp2_lastErrorText(ftp));
CkFtp2_Dispose(ftp);
return;
}
printf("Compatibility option toggled.\n");
success = CkFtp2_Disconnect(ftp);
if (success == FALSE) {
printf("%s\n",CkFtp2_lastErrorText(ftp));
CkFtp2_Dispose(ftp);
return;
}
CkFtp2_Dispose(ftp);
}