Sample code for 30+ languages & platforms
Unicode C

Execute an FTP Upload Plan

See more FTP Examples

Demonstrates the Chilkat Ftp2.PutPlan method, which executes a previously created upload plan. The first argument is the plan text and the second is the local path of a completion log that records each successful operation.

Note: The local paths are relative to the application's current working directory. Absolute paths may also be used. Supply the paths appropriate to your own environment.

Background: The completion log is what makes plan execution resumable: each successful upload is recorded, so if a run is interrupted, re-executing the same plan skips the operations already logged and continues where it left off — invaluable for a large transfer over a flaky connection. The plan's stored absolute remote paths are used regardless of the current remote directory, so execution is independent of session state.

Chilkat Unicode C Downloads

Unicode C
#include <C_CkFtp2W.h>
#include <C_CkStringBuilderW.h>

void ChilkatSample(void)
    {
    BOOL success;
    HCkFtp2W ftp;
    HCkStringBuilderW sbPlan;
    const wchar_t *plan;

    success = FALSE;

    //  Demonstrates the Ftp2.PutPlan method, which executes a previously created upload plan.  The 1st
    //  argument is the plan text and the 2nd is the local path of a completion log.

    ftp = CkFtp2W_Create();

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

    success = CkFtp2W_Connect(ftp);
    if (success == FALSE) {
        wprintf(L"%s\n",CkFtp2W_lastErrorText(ftp));
        CkFtp2W_Dispose(ftp);
        return;
    }

    success = CkFtp2W_ChangeRemoteDir(ftp,L"public_html");
    if (success == FALSE) {
        wprintf(L"%s\n",CkFtp2W_lastErrorText(ftp));
        CkFtp2W_Dispose(ftp);
        return;
    }

    //  Load a plan that was previously created with CreatePlan.
    sbPlan = CkStringBuilderW_Create();
    success = CkStringBuilderW_LoadFile(sbPlan,L"qa_output/upload_plan.txt",L"utf-8");
    if (success == FALSE) {
        wprintf(L"%s\n",CkStringBuilderW_lastErrorText(sbPlan));
        CkFtp2W_Dispose(ftp);
        CkStringBuilderW_Dispose(sbPlan);
        return;
    }

    plan = CkStringBuilderW_getAsString(sbPlan);

    //  Execute the plan.  Each successful operation is recorded in the completion log, which lets an
    //  interrupted run be resumed without repeating completed uploads.  The plan uses its stored
    //  absolute remote paths even if the current remote directory has changed.
    success = CkFtp2W_PutPlan(ftp,plan,L"qa_output/upload_done.log");
    if (success == FALSE) {
        wprintf(L"%s\n",CkFtp2W_lastErrorText(ftp));
        CkFtp2W_Dispose(ftp);
        CkStringBuilderW_Dispose(sbPlan);
        return;
    }

    wprintf(L"Upload plan executed.\n");

    success = CkFtp2W_Disconnect(ftp);
    if (success == FALSE) {
        wprintf(L"%s\n",CkFtp2W_lastErrorText(ftp));
        CkFtp2W_Dispose(ftp);
        CkStringBuilderW_Dispose(sbPlan);
        return;
    }



    CkFtp2W_Dispose(ftp);
    CkStringBuilderW_Dispose(sbPlan);

    }