FileProvider:从FTP服务器下载的内容未显示在目录中

时间:2020-06-07 01:25:25

标签: ios swift ftp

我正在尝试从某个服务器下载文件(即“ xp-en.zip”)。我已经使用contentsOfDirectory(::)检查了该文件是否存在,但是由于某种原因,下载完成后,该文件未显示在应该复制到的目录中。我正在使用XCode,并且我认为它可能与应用程序的权限有关(因为目标目录为.documentDirectory),但是我尝试将其更改为主要包无济于事。

我还尝试了从另一台服务器('speedtest.tele2.net')下载,但也无法正常工作。

let credential = URLCredential(user: "anonymous", password: "123456", persistence: .permanent)
let fileManager = FileManager.default

func FTPDownloadUpload(download: Bool = true, server: String, path: String){
    let localFilePath = fileManager.urls(for: .documentDirectory, in: .userDomainMask).first!
    guard let url = URL(string: server) else{
        print("Invalid URL")
        return
    }
    let FTPProvider = FTPFileProvider(baseURL: URL(string: "ftp://" + server)!, mode: .passive, credential: credential, cache: URLCache())
    if download{
        FTPProvider?.copyItem(path: "/" + path, toLocalURL: localFilePath, completionHandler: {x in print("Download completed")})
        //I know this completionHandler closure kinda sucks but I don't know what else to put inside it. Keep in mind my program doesn't have anything to do after calling this function

    }else{
        //This is the upload section. Didn't include it to keep the code shorter
    }
}

我的函数调用是:

FTPDownloadUpload(server: "176.74.128.88", path: "xp-en.zip")

0 个答案:

没有答案