FileProvider
FileProvider copied to clipboard
Connection stays open after FTP upload
Hi,
I'm trying to upload a single picture via FTP with the following script:
let credential = URLCredential(user: "xxxxxxxx", password: "xxxxxxxx", persistence: .none)
let cache = URLCache()
let ftpProvider = FTPFileProvider(baseURL: URL(string: "ftp://xxx.xxx.xxx.xxx")!, mode: .passive, credential: credential, cache: cache)
ftpProvider?.copyItem(localFile: in_ImageUrl, to: "\(Account.shared().Guid).\(in_ImageUrl.pathExtension)", completionHandler: { error in
if error == nil {
print("ready")
} else {
print("\(String(describing: error))")
}
})
The file will be sent to the server but in most cases the connection is never closed so the file stays locked. I've debugged a lot but I didn't get it. The app sends a "quit" command via "ftpQuit" but it doesn't arrive on the FTP server.
The FTP server stays in the following state:

Is this a Server issue, an issue in my script or a FilesProvider issue?
Thank you
If you check codes here, it's intentional behavior to workaround a bug in iOS 11 CFStream which closes write stream prematurely. To prevent truncated uploaded file, I have set a timeout.
I didn't succeed to find another way, but if you think there is other ways to address this issue, please open a pull request.
I'm also trying to figure this out, since the workaround is a major limitation to (recursive fallback) folder copying: servers refuse to further open connections once you have a dozen hanging uploads.
Is it possible that the workaround sleep isn't really working and the problem is somewhere else entirely? I've been getting truncated uploads despite the sleep.
Indeed I must find a way to use native URLSessionStreamTask instead of my implementation. But it doesn't establish data connection correctly.