Sample code for 30+ languages & platforms
Unicode C

FTP Bandwidth Throttle for Downloads

See more FTP Examples

Demonstrates the Chilkat FTP2 download bandwidth throttling property : BandwidthThrottleDown.

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

    // To use FTP bandwidth throttling, set the BandwidthThrottleDown
    // property to a maximum desired bytes/second:
    // This example limits the download to 50K per second.
    CkFtp2W_putBandwidthThrottleDown(ftp,50000);

    // The default data transfer mode is "Active" as opposed to "Passive".

    // 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;
    }

    // Download a file.
    localFilename = L"hamlet.xml";
    remoteFilename = L"hamlet.xml";

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

    }