Sample code for 30+ languages & platforms
Swift

Use Explicit FTP over TLS

See more FTP Examples

Demonstrates how to connect to an FTP server using explicit FTP over TLS.

Chilkat Swift Downloads

Swift

func chilkatTest() {
    var success: Bool = false

    // This example requires the Chilkat API to have been previously unlocked.
    // See Global Unlock Sample for sample code.

    let ftp = CkoFtp2()!

    ftp.hostname = "ftp.your-ftp-server.com"
    ftp.username = "ftpAccountLogin"
    ftp.password = "ftpAccountPassword"

    // Indicate that the "AUTH TLS" command should be use to convert the connection to TLS
    // after the initial TCP connection to port 21 is established.
    ftp.authTls = true

    // Connect and convert the connection to TLS automatically.
    success = ftp.connectOnly()
    if success != true {
        print("\(ftp.lastErrorText!)")
        return
    }

    success = ftp.loginAfterConnectOnly()
    if success != true {
        print("\(ftp.lastErrorText!)")
        return
    }

    print("TLS connection established and successfully authenticated.")

}