Swift
Swift
FTP Upload / Download to a BinData Object
Demonstrates how to FTP upload the contents of a BinData object, and FTP downloads to the a BinData object.Chilkat Swift Downloads
func chilkatTest() {
var success: Bool = false
// This example assumes Chilkat Ftp2 to have been previously unlocked.
// See Unlock Ftp2 for sample code.
let ftp = CkoFtp2()!
ftp.hostname = "www.my-ftp-server.com"
ftp.username = "mFtpLogin"
ftp.password = "myFtpPassword"
// Connect to the FTP server.
success = ftp.connectOnly()
if success != true {
print("\(ftp.lastErrorText!)")
return
}
// Authenticate with the FTP server.
success = ftp.loginAfterConnectOnly()
if success != true {
print("\(ftp.lastErrorText!)")
return
}
let bdA = CkoBinData()!
bdA.loadFile(path: "qa_data/jpg/penguins.jpg")
// Upload the contents of bdA to the FTP server.
var remoteFilename: String? = "penguins.jpg"
success = ftp.putFileBd(binData: bdA, remoteFilePath: remoteFilename)
if success != true {
print("\(ftp.lastErrorText!)")
return
}
// Download...
let bdB = CkoBinData()!
success = ftp.getFileBd(remoteFilePath: remoteFilename, binData: bdB)
if success != true {
print("\(ftp.lastErrorText!)")
return
}
// Verify that bdA and bdB have the exact same contents.
print("size of bdA: \(bdA.numBytes.intValue)")
if bdA.contentsEqual(binData: bdB) == true {
print("Contents are equal. Success.")
}
else {
print("Contents are NOT equal. Failed.")
}
ftp.disconnect()
}