Sample code for 30+ languages & platforms
C

Determine if Connected and Logged On

See more FTP Examples

The IsConnected property indicates whether or not the FTP component has a valid TCP/IP connection (and is logged on) to the FTP server.

Chilkat C Downloads

C
#include <C_CkFtp2.h>

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

    success = FALSE;

    // This example requires the Chilkat API to have been previously unlocked.
    // See Global Unlock Sample for sample code.

    ftp = CkFtp2_Create();

    CkFtp2_putHostname(ftp,"ftp.example.com");
    CkFtp2_putUsername(ftp,"mylogin");
    CkFtp2_putPassword(ftp,"mypassword");

    // Connect and login to the FTP server.
    success = CkFtp2_Connect(ftp);
    if (success != TRUE) {
        printf("%s\n",CkFtp2_lastErrorText(ftp));
        CkFtp2_Dispose(ftp);
        return;
    }

    // ...

    // At any point in an FTP session, the IsConnected property
    // can be checked to determine if the component has remained
    // connected to the FTP server.
    if (CkFtp2_getIsConnected(ftp) == TRUE) {
        printf("Connected!\n");
    }
    else {
        printf("Not connected!\n");
    }

    // ...

    success = CkFtp2_Disconnect(ftp);


    CkFtp2_Dispose(ftp);

    }