Sample code for 30+ languages & platforms
Lua

Upload Directory Tree

See more FTP Examples

Upload an entire directory tree from the local filesystem to an FTP server.

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.keep_session_log = true

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

-- Set the current remote directory to the root where the
-- directory tree will be uploaded.
success = ftp:change_remote_dir("/something")
if not success then
    print(ftp.last_error_text)
    return
end

-- Upload the entire directory tree rooted at c:/temp/something
success = ftp:put_tree("c:/temp/something")
if not success then
    print(ftp.last_error_text)
    return
end

success = ftp:disconnect()

print(ftp.session_log)