Sample code for 30+ languages & platforms
Unicode C

Simple FTP Download

See more FTP Examples

Simple example to download a file from an FTP server.

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.someFtpServer.com");
    CkFtp2W_putUsername(ftp,L"myLogin");
    CkFtp2W_putPassword(ftp,L"myPassword");

    // 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 file is located.
    // This step is only necessary if the file is not in the root directory
    // for the FTP account.
    success = CkFtp2W_ChangeRemoteDir(ftp,L"junk");
    if (success != TRUE) {
        wprintf(L"%s\n",CkFtp2W_lastErrorText(ftp));
        CkFtp2W_Dispose(ftp);
        return;
    }

    localFilename = L"c:/temp/hamlet.xml";
    remoteFilename = L"hamlet.xml";

    // Download a file.
    success = CkFtp2W_GetFile(ftp,remoteFilename,localFilename);
    if (success != TRUE) {
        wprintf(L"%s\n",CkFtp2W_lastErrorText(ftp));
        CkFtp2W_Dispose(ftp);
        return;
    }

    success = CkFtp2W_Disconnect(ftp);

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


    CkFtp2W_Dispose(ftp);

    }