FileProvider icon indicating copy to clipboard operation
FileProvider copied to clipboard

Connection stays open after FTP upload

Open ralf1991 opened this issue 7 years ago • 3 comments
trafficstars

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: ftpupload

Is this a Server issue, an issue in my script or a FilesProvider issue?

Thank you

ralf1991 avatar Aug 14 '18 05:08 ralf1991

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.

amosavian avatar Aug 14 '18 16:08 amosavian

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.

sashoism avatar Aug 15 '18 08:08 sashoism

Indeed I must find a way to use native URLSessionStreamTask instead of my implementation. But it doesn't establish data connection correctly.

amosavian avatar Aug 15 '18 16:08 amosavian