Sample code for 30+ languages & platforms
Node.js

Get Filenames in a Remote Directory

Gets the names of files in a remote FTP directory.

Chilkat Node.js Downloads

Node.js
NODEJS_PRELUDE

function chilkatExample() {

    var success = false;

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

    var ftp = new chilkat.Ftp2();

    ftp.Hostname = "ftp.example.com";
    ftp.Username = "myLogin";
    ftp.Password = "myPassword";
    //  Use explicit TLS
    ftp.AuthTls = true;
    ftp.Port = 21;

    //  Connect and login to the FTP server.
    success = ftp.Connect();
    if (success !== true) {
        console.log(ftp.LastErrorText);
        return;
    }

    //  Iterate over .txt files.
    ftp.ListPattern = "*.txt";
    var n = ftp.GetDirCount();
    console.log("n = " + n);

    var i = 0;
    while (i < n) {

        console.log(i + ": " + ftp.GetFilename(i));

        i = i+1;
    }


}

chilkatExample();