我需要将文件上传到 FTP 服务器,检查文件夹是否存在,如果不存在,请创建它。我找到了 Amir Abbas Mousavian 的 FileProvider。我安装了所有东西并实现了以下代码:
let credential = URLCredential(user: "user", password: "password", persistence: .permanent)
let ftpProvider = FTPFileProvider(baseURL: URL(string:"cflm.org")!, mode: .active, credential: credential, cache: nil)
ftpProvider?.delegate = self as! FileProviderDelegate
ftpProvider?.contentsOfDirectory(path: "/", completionHandler: {
contents, error in
for file in contents {
print("Name: \(file.name)")
print("Size: \(file.size)")
print("Creation Date: \(file.creationDate)")
print("Modification Date: \(file.modifiedDate)")
}
})
当我运行代码时,contentsOfDirectory 的 completionHandler 永远不会触发。有谁知道我做错了什么或有其他方法可以执行我需要的 FTP 功能?