Sample code for 30+ languages & platforms
Unicode C++

Send an FTP SITE Command

See more FTP Examples

Demonstrates the Chilkat Ftp2.Site method, which sends a server-specific SITE command. The only argument is the text following SITE, for example CHMOD 644 index.html.

Background: SITE is FTP's extension point for features outside the standard — each server defines its own subcommands. The best-known is SITE CHMOD on Unix servers to set file permissions, but others cover mainframe dataset attributes, quotas, and more. Because these are non-standard and often privileged, expect them to vary by server and to require appropriate rights.

Chilkat Unicode C++ Downloads

Unicode C++
#include <CkFtp2W.h>

void ChilkatSample(void)
    {
    bool success = false;

    //  Demonstrates the Ftp2.Site method, which sends a server-specific SITE command.  The only
    //  argument is the text following "SITE".

    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");

    //  Connect and log in (Connect performs both).
    success = ftp.Connect();
    if (success == false) {
        wprintf(L"%s\n",ftp.lastErrorText());
        return;
    }

    //  SITE subcommands are defined by the server, not by the FTP standard, and may require special
    //  permissions.  A common example is changing file permissions on a Unix FTP server.
    success = ftp.Site(L"CHMOD 644 public_html/index.html");
    if (success == false) {
        wprintf(L"%s\n",ftp.lastErrorText());
        return;
    }

    wprintf(L"SITE command accepted.\n");

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