Sample code for 30+ languages & platforms
C

Get Filenames in a Remote Directory

Gets the names of files in a remote FTP directory.

Chilkat C Downloads

C
#include <C_CkFtp2.h>

void ChilkatSample(void)
    {
    BOOL success;
    HCkFtp2 ftp;
    int n;
    int i;

    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");
    //  Use explicit TLS
    CkFtp2_putAuthTls(ftp,TRUE);
    CkFtp2_putPort(ftp,21);

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

    //  Iterate over .txt files.
    CkFtp2_putListPattern(ftp,"*.txt");
    n = CkFtp2_GetDirCount(ftp);
    printf("n = %d\n",n);

    i = 0;
    while (i < n) {

        printf("%d: %s\n",i,CkFtp2_getFilename(ftp,i));

        i = i + 1;
    }



    CkFtp2_Dispose(ftp);

    }