Sample code for 30+ languages & platforms
Unicode 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 Unicode C++ Downloads

Unicode C++
#include <CkFtp2W.h>

void ChilkatSample(void)
    {
    bool 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.

    CkFtp2W ftp;

    ftp.put_Hostname(L"ftp.example.com");
    ftp.put_Username(L"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.put_Password(L"myPassword");

    success = ftp.Connect();
    if (success == false) {
        wprintf(L"%s\n",ftp.lastErrorText());
        return;
    }

    //  Enable a recognized compatibility workaround.  Option-name matching is case-insensitive.
    success = ftp.SetOption(L"Microsoft-TLS-1.2-Workaround");
    if (success == false) {
        wprintf(L"%s\n",ftp.lastErrorText());
        return;
    }

    //  To disable it, prefix the name with "No-":
    success = ftp.SetOption(L"No-Microsoft-TLS-1.2-Workaround");
    if (success == false) {
        wprintf(L"%s\n",ftp.lastErrorText());
        return;
    }

    wprintf(L"Compatibility option toggled.\n");

    success = ftp.Disconnect();
    if (success == false) {
        wprintf(L"%s\n",ftp.lastErrorText());
        return;
    }
    }