Sample code for 30+ languages & platforms
Lianja

Get Filenames in a Remote Directory

Gets the names of files in a remote FTP directory.

Chilkat Lianja Downloads

Lianja
llSuccess = .F.

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

loFtp = createobject("CkFtp2")

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

// Connect and login to the FTP server.
llSuccess = loFtp.Connect()
if (llSuccess <> .T.) then
    ? loFtp.LastErrorText
    release loFtp
    return
endif

// Iterate over .txt files.
loFtp.ListPattern = "*.txt"
n = loFtp.GetDirCount()
? "n = " + str(n)

i = 0
do while i < n

    ? str(i) + ": " + loFtp.GetFilename(i)

    i = i + 1
enddo


release loFtp