Sample code for 30+ languages & platforms
Lua

SFTP Download Files Matching a Pattern

See more SFTP Examples

Demonstrates how to download files in a directory matching one or more patterns (such as "*.zip" or "abc*_*0719.csv".

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 sftp = chilkat.SFtp.new()

local success = sftp:connect("my-ssh-server.com", 22)
if success then
    success = sftp:authenticate_pw("mySshLogin", "mySshPassword")
end

if success then
    success = sftp:initialize_sftp()
end

if not success then
    print(sftp.last_error_text)
    return
end

-- The SyncTreeDownload method can be used non-recursively to download all files matching a set of patterns.

-- This example will download all files, but only those files having filenames
-- that match *.csv and *.eml
sftp.sync_must_match = "*.eml; *.gif"

local remoteDir = "syncDownloadTest/someDir"
local localDir = "qa_output"

-- mode=0: Download all matching files according to SyncMustMatch
local mode = 0

-- do not recursively traverse the remote directory tree.
local recursive = false

success = sftp:sync_tree_download(remoteDir, localDir, mode, recursive)
if not success then
    print(sftp.last_error_text)
    return
end

print("Success.")