Lua
Lua
Get FTP Directory Listing Information
See more FTP Examples
_LANGUAGE_ example showing how to get information about files and subdirectories in the current remote FTP directory.Chilkat Lua Downloads
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 = "login"
ftp.password = "password"
-- Connect and login to the FTP server.
local success = ftp:connect()
if not success then
print(ftp.last_error_text)
return
end
-- The ListPattern property is our directory listing filter.
-- The default value is "*", which includes everything.
print(ftp.list_pattern)
-- To get file and sub-directory information, simply
-- loop from 0 to ftp.GetDirCount() - 1
local n = ftp:get_dir_count()
if n < 0 then
print(ftp.last_error_text)
return
end
if n > 0 then
for i = 0, n - 1 do
-- Display the filename
print(ftp:get_filename(i))
-- Display the file size (in bytes)
print(ftp:get_size(i))
-- Is this a sub-directory?
if ftp:get_is_directory(i) then
print(".. this is a sub-directory")
end
print("--")
end
end
print("-----------------------------------")
-- Only files and directories
-- matching the ListPattern are returned.
ftp.list_pattern = "*.asp"
n = ftp:get_dir_count()
if n < 0 then
print(ftp.last_error_text)
return
end
if n > 0 then
for i = 0, n - 1 do
-- Display the filename
print(ftp:get_filename(i))
-- Display the file size (in bytes)
print(ftp:get_size(i))
print("--")
end
end
success = ftp:disconnect()