Sample code for 30+ languages & platforms
Lua Requires Chilkat v11.0.0+

FTP Connect, Examine Server Certificate, and then Authenticate

See more FTP Examples

Demonstrates how to connect to an FTP server, examine the server's SSL/TLS certificate, and then, if it meets the application's security requirements, proceed to authenticate.

Chilkat Lua Downloads

Lua
local chilkat = require("chilkat")

-- This example assumes Chilkat Ftp2 to have been previously unlocked.
-- See Unlock Ftp2 for sample code.

local ftp = chilkat.Ftp2.new()

ftp.hostname = "www.authtls-ftps-server.com"
ftp.username = "FTP_LOGIN"
ftp.password = "FTP_PASSWORD"
ftp.auth_tls = true
ftp.port = 21

-- Connect to the FTP server using explicit TLS (AUTH TLS).
local success = ftp:connect_only()
if not success then
    print(ftp.last_error_text)
    return
end

-- Get the FTP server's certificate.
local serverCert = chilkat.Cert.new()
success = ftp:get_server_cert(serverCert)
if not success then
    print(ftp.last_error_text)
    return
end

-- Now that we have the certificate, we can check it in any way we desire.
-- (See the online reference documentation for the certificate object's methods
-- and properties)...

-- Assuming the certificate is OK, proceed to authenticate with the FTP server.
success = ftp:login_after_connect_only()
if not success then
    print(ftp.last_error_text)
    return
end

-- Proceed with uploading/download files, etc...
--

ftp:disconnect()
print("Success.")