Sample code for 30+ languages & platforms
Lua

FTP Download File to a Stream

Demonstrates how to FTP download a file to a Chilkat stream.

Chilkat Lua Downloads

Lua
local chilkat = require("chilkat")

-- This example assumes the Chilkat FTP2 API to have been previously unlocked.
-- See FTP2 Unlock Sample for sample code.

local ftp = chilkat.Ftp2.new()

ftp.hostname = "my-ftp-server.com"
ftp.port = 21
ftp.username = "mFtpLogin"
ftp.password = "myFtpPassword"
ftp.auth_tls = true
ftp.passive = true

-- Connect and login to the FTP server using TLS.
local success = ftp:connect()
if not success then
    print(ftp.last_error_text)
    return
end

-- Move to the sub-directory (from the FTP user's home directory) where the file is located.
success = ftp:change_remote_dir("temp")
if not success then
    print(ftp.last_error_text)
    return
end

-- Stream to this local file:
local streamObj = chilkat.Stream.new()
streamObj.sink_file = "c:/temp/qa_output/penguins2.jpg"

success = ftp:get_file_to_stream("penguins2.jpg", streamObj)
if not success then
    print(ftp.last_error_text)
    return
end

ftp:disconnect()

print("Success.")