Sample code for 30+ languages & platforms
Lua

Download Multiple Files Matching Pattern

See more FTP Examples

The MGetFiles method can be called to download all files matching a wildcarded filename pattern.

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 = "myUsername"
ftp.password = "myPassword"
ftp.port = 21
ftp.auth_tls = true

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

-- Change to the remote directory where the files are located.
-- This step is only necessary if the files are not in the root directory
-- of the FTP account.
success = ftp:change_remote_dir("qa")
if not success then
    print(ftp.last_error_text)
    return
end

-- Download all files with filenames matching "*.txt";
-- The files are downloaded into c:/temp/qa_output
local numFilesDownloaded = ftp:mget_files("*.txt", "c:/temp/qa_output")
if numFilesDownloaded < 0 then
    print(ftp.last_error_text)
    return
end

success = ftp:disconnect()

print(numFilesDownloaded .. " Files Downloaded!")