Sample code for 30+ languages & platforms
C

Upload a Large File in Chunks (FTP)

See more FTP Examples

Demonstrates the Chilkat Ftp2.LargeFileUpload method, which uploads a local file as a sequence of transfers, each up to a given chunk size. The arguments are the local path, the remote path, and the chunk size in bytes.

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: Some servers, proxies, or firewalls impose a limit on the size or duration of a single data transfer, which a very large file can exceed. This method sidesteps that by sending the file in pieces — the first with STOR to create or replace the file, each subsequent one appended — so no single transfer is oversized. Choose a chunk size comfortably under whatever limit you are working around.

Chilkat C Downloads

C
#include <C_CkFtp2.h>

void ChilkatSample(void)
    {
    BOOL success;
    HCkFtp2 ftp;
    int chunkSize;

    success = FALSE;

    //  Demonstrates the Ftp2.LargeFileUpload method, which uploads a local file as a sequence of
    //  transfers, each up to a given chunk size.  The 1st argument is the local path, the 2nd is the
    //  remote path, and the 3rd is the chunk size in bytes.

    ftp = CkFtp2_Create();

    CkFtp2_putHostname(ftp,"ftp.example.com");
    CkFtp2_putUsername(ftp,"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.
    CkFtp2_putPassword(ftp,"myPassword");

    success = CkFtp2_Connect(ftp);
    if (success == FALSE) {
        printf("%s\n",CkFtp2_lastErrorText(ftp));
        CkFtp2_Dispose(ftp);
        return;
    }

    //  The first chunk is sent with STOR (creating/replacing the remote file); each later chunk is
    //  appended.  Uploading in chunks can work around server or network limits on a single transfer.
    chunkSize = 10485760;
    success = CkFtp2_LargeFileUpload(ftp,"qa_data/bigfile.zip","uploads/bigfile.zip",chunkSize);
    if (success == FALSE) {
        printf("%s\n",CkFtp2_lastErrorText(ftp));
        CkFtp2_Dispose(ftp);
        return;
    }

    printf("Large file uploaded.\n");

    success = CkFtp2_Disconnect(ftp);
    if (success == FALSE) {
        printf("%s\n",CkFtp2_lastErrorText(ftp));
        CkFtp2_Dispose(ftp);
        return;
    }



    CkFtp2_Dispose(ftp);

    }