Sample code for 30+ languages & platforms
Lua Requires Chilkat v9.5.0.51+

FTP through HTTP Tunnel (FTP over HTTP Proxy)

See more FTP Examples

FTP through an HTTP tunnel (via an HTTP proxy server that supports HTTP tunneling).

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"

-- Set the HTTP proxy server properties.
-- This is to connect via HTTP/1.1 using CONNECT method
ftp.http_proxy_hostname = "192.168.1.127"
ftp.http_proxy_port = 8080

-- If the proxy server requires authentication...
ftp.http_proxy_username = "myProxyUsername"
ftp.http_proxy_password = "myProxyPassword"

-- FTP over an HTTP proxy requires that FTP Passive mode be used
-- for data transfers. It is not possible to use non-passive (active) mode
-- for FTP over HTTP.
ftp.passive = true

-- 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 file will be uploaded.
success = ftp:change_remote_dir("junk")
if not success then
    print(ftp.last_error_text)
    return
end

-- Upload a file.
local localFilename = "c:/temp/hamlet.xml"
local remoteFilename = "hamlet.xml"

success = ftp:put_file(localFilename, remoteFilename)
if not success then
    print(ftp.last_error_text)
    return
end

success = ftp:disconnect()

print("File Uploaded!")