Sample code for 30+ languages & platforms
Lua

Quote and SendCommand

See more FTP Examples

Demonstrate the Quote and SendCommand methods.

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 = "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

-- Tell the FTP object to keep an in-memory session log
-- so we can see the commands sent to the server,
-- and the responses received back.
ftp.keep_session_log = true

-- Change the current remote directory via the Quote method:
success = ftp:quote("CWD junk")
if not success then
    print(ftp.last_error_text)
    return
end

-- Move back up
-- In this case, ChangeRemoteDir sends "CWD .." to the FTP server.
success = ftp:change_remote_dir("..")
if not success then
    print(ftp.last_error_text)
    return
end

-- Do the same via the SendCommand method where the
-- raw FTP server response is returned:
local serverResponse = ftp:send_command("CWD junk")
if not ftp.last_method_success then
    print(ftp.last_error_text)
else
    print(serverResponse)
end

success = ftp:disconnect()

print("Session Log:")
print(ftp.session_log)