Swift
Swift
Get Filenames in a Remote Directory
Gets the names of files in a remote FTP directory.Chilkat Swift Downloads
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.example.com"
ftp.username = "myLogin"
ftp.password = "myPassword"
// Use explicit TLS
ftp.authTls = true
ftp.port = 21
// Connect and login to the FTP server.
success = ftp.connect()
if success != true {
print("\(ftp.lastErrorText!)")
return
}
// Iterate over .txt files.
ftp.listPattern = "*.txt"
var n: Int = ftp.getDirCount().intValue
print("n = \(n)")
var i: Int = 0
while i < n {
print("\(i): \(ftp.getFilename(index: i)!)")
i = i + 1
}
}