Sample code for 30+ languages & platforms
Unicode C

Set FTP Connection and Read Timeouts

See more FTP Examples

Demonstrates the timeout properties ConnectTimeout, ReadTimeout, and IdleTimeoutMs.

Background: The three timeouts guard different phases: ConnectTimeout (in seconds) bounds how long a connection attempt blocks so an unreachable server fails promptly; ReadTimeout (seconds) limits how long a data connection may stall without new data; and IdleTimeoutMs (milliseconds) caps a lack of forward progress overall. Tuning them prevents a hung server or flaky link from freezing an automated job indefinitely.

Chilkat Unicode C Downloads

Unicode C
#include <C_CkFtp2W.h>

void ChilkatSample(void)
    {
    BOOL success;
    HCkFtp2W ftp;

    success = FALSE;

    ftp = CkFtp2W_Create();

    CkFtp2W_putHostname(ftp,L"ftp.example.com");
    CkFtp2W_putUsername(ftp,L"myFtpLogin");

    //  Maximum seconds to wait for the TCP connection to be accepted.
    CkFtp2W_putConnectTimeout(ftp,15);

    //  Maximum seconds a data connection may go without receiving more data before timing out.
    CkFtp2W_putReadTimeout(ftp,30);

    //  Maximum milliseconds without a control-channel response or forward progress before failing.
    CkFtp2W_putIdleTimeoutMs(ftp,20000);

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

    wprintf(L"Connected with custom timeouts.\n");

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



    CkFtp2W_Dispose(ftp);

    }