Sample code for 30+ languages & platforms
Unicode C

Using the FTP Session Log

See more FTP Examples

The Chilkat FTP component can keep a session log if the KeepSessionLog property is turned on. This is helpful in debugging problems. Chilkat support will usually ask for a session log when working to resolve your problem, because it contains a log of the exact commands sent to the FTP server, and the exact responses received.

Chilkat Unicode C Downloads

Unicode C
#include <C_CkFtp2W.h>

void ChilkatSample(void)
    {
    BOOL success;
    HCkFtp2W ftp;
    const wchar_t *localFilename;
    const wchar_t *remoteFilename;

    success = FALSE;

    // This example requires the Chilkat API to have been previously unlocked.
    // See Global Unlock Sample for sample code.

    ftp = CkFtp2W_Create();

    CkFtp2W_putHostname(ftp,L"ftp.example.com");
    CkFtp2W_putUsername(ftp,L"login");
    CkFtp2W_putPassword(ftp,L"password");

    // Set the KeepSessionLog property in order to keep a session log.
    // The session log will continuously grow in memory.  The
    // ClearSessionLog method may be called to clear it.  The session
    // logging may be turned on/off at any point.
    CkFtp2W_putKeepSessionLog(ftp,TRUE);

    // Connect and login to the FTP server.
    success = CkFtp2W_Connect(ftp);
    if (success != TRUE) {
        wprintf(L"%s\n",CkFtp2W_lastErrorText(ftp));
        CkFtp2W_Dispose(ftp);
        return;
    }

    // Change to the remote directory where the existing file is located.
    success = CkFtp2W_ChangeRemoteDir(ftp,L"junk");
    if (success != TRUE) {
        wprintf(L"%s\n",CkFtp2W_lastErrorText(ftp));
        CkFtp2W_Dispose(ftp);
        return;
    }

    // To clear the SessionLog at any point, call ClearSessionLog:
    // call ftp.ClearSessionLog();

    // Append moreHamlet.txt to hamlet.txt on the FTP server.
    localFilename = L"moreHamlet.txt";
    remoteFilename = L"hamlet.txt";

    success = CkFtp2W_AppendFile(ftp,localFilename,remoteFilename);
    if (success != TRUE) {
        wprintf(L"%s\n",CkFtp2W_lastErrorText(ftp));
        CkFtp2W_Dispose(ftp);
        return;
    }

    success = CkFtp2W_Disconnect(ftp);

    // Display the entire session log:
    wprintf(L"%s\n",CkFtp2W_sessionLog(ftp));

    wprintf(L"File Appended!\n");


    CkFtp2W_Dispose(ftp);

    }