Sample code for 30+ languages & platforms
Lua

Get Filenames in a Remote Directory

Gets the names of files in a remote FTP directory.

Chilkat Lua Downloads

Lua
local chilkat = require("chilkat")

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

local ftp = chilkat.Ftp2.new()

ftp.hostname = "ftp.example.com"
ftp.username = "myLogin"
ftp.password = "myPassword"
-- Use explicit TLS
ftp.auth_tls = true
ftp.port = 21

-- Connect and login to the FTP server.
local success = ftp:connect()
if not success then
    print(ftp.last_error_text)
    return
end

-- Iterate over .txt files.
ftp.list_pattern = "*.txt"
local n = ftp:get_dir_count()
print("n = " .. n)

local i = 0
while i < n do
    print(i .. ": " .. ftp:get_filename(i))

    i = i + 1
end