Sample code for 30+ languages & platforms
Swift

FTP Download File to a Stream

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

Chilkat Swift Downloads

Swift

func chilkatTest() {
    var success: Bool = false

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

    let ftp = CkoFtp2()!

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

    // Connect and login to the FTP server using TLS.
    success = ftp.connect()
    if success != true {
        print("\(ftp.lastErrorText!)")
        return
    }

    // Move to the sub-directory (from the FTP user's home directory) where the file is located.
    success = ftp.changeRemoteDir(relativeDirPath: "temp")
    if success == false {
        print("\(ftp.lastErrorText!)")
        return
    }

    // Stream to this local file:
    let streamObj = CkoStream()!
    streamObj.sinkFile = "c:/temp/qa_output/penguins2.jpg"

    success = ftp.getFile(toStream: "penguins2.jpg", to: streamObj)
    if success == false {
        print("\(ftp.lastErrorText!)")
        return
    }

    ftp.disconnect()

    print("Success.")

}