Sample code for 30+ languages & platforms
Lua

FTPS with Mutual TLS Authentication (TLS Client Certificate)

See more FTP Examples

Demonstrates how to do mutual TLS authentication (using a client certificate from a .pfx/.p12).

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.port = 21

-- If using implicit TLS, you probably want port 990..
ftp.port = 990

-- Set this to false for implicit TLS, otherwise set to true for explicit TLS (where port is typically 21).
ftp.auth_tls = false

-- Set this to true for implicit TLS, otherwise set to false.
ftp.ssl = true

local cert = chilkat.Cert.new()
local success = cert:load_pfx_file("qa_data/pfx/example.pfx", "pfx_password")
if not success then
    print(cert.last_error_text)
    return
end

-- Use this certificate for our TLS mutually authenticated connection:
success = ftp:set_ssl_client_cert(cert)
if not success then
    print(cert.last_error_text)
    return
end

-- Establish the TLS connection with the FTP server.
success = ftp:connect_only()
if not success then
    print(ftp.last_error_text)
    return
end

-- If a login is required, then login with the FTP account login/password.
ftp.username = "myLogin"
ftp.password = "myPassword"
success = ftp:login_after_connect_only()
if not success then
    print(ftp.last_error_text)
    return
end

-- Do whatever you're doing to do ...
-- upload files, download files, etc...

-- .....
-- .....

success = ftp:disconnect()