Sample code for 30+ languages & platforms
Lua

Delete Files Matching Pattern

See more FTP Examples

The DeleteMatching method deletes all files in the current remote directory matching a wildcarded filename.

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 = "www.chilkatsoft.com"
ftp.username = "MyLogin"
ftp.password = "MyPassword"

-- 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 to be deleted are located.
-- for the FTP account.
success = ftp:change_remote_dir("junk")
if not success then
    print(ftp.last_error_text)
    return
end

-- Delete all files with filenames matching "ftp_*.asp"
local numDeleted = ftp:delete_matching("ftp_*.asp")
if numDeleted < 0 then
    print(ftp.last_error_text)
    return
end

success = ftp:disconnect()

print(numDeleted .. " Files Deleted!")