Sample code for 30+ languages & platforms
Swift

Upload Directory Tree

See more FTP Examples

Upload an entire directory tree from the local filesystem to an FTP server.

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.keepSessionLog = true

    ftp.hostname = "ftp.example.com"
    ftp.username = "login"
    ftp.password = "password"

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

    // Set the current remote directory to the root where the
    // directory tree will be uploaded.
    success = ftp.changeRemoteDir(relativeDirPath: "/something")
    if success != true {
        print("\(ftp.lastErrorText!)")
        return
    }

    // Upload the entire directory tree rooted at c:/temp/something
    success = ftp.putTree(localDir: "c:/temp/something")
    if success != true {
        print("\(ftp.lastErrorText!)")
        return
    }

    success = ftp.disconnect()

    print("\(ftp.sessionLog!)")

}