Open Nathipha opened 5 years ago
Update: I created a simple "sample.txt" at the root of my ftp server (text inside : "Hello world from sample.txt!"), then tried to just read the file to later save it myself. For this I'm using this code from the "Sample-iOS.swift" file here.
ftpProvider?.contents(path: source, completionHandler: {
contents, error in
if let contents = contents {
print(String(data: contents, encoding: .utf8))
}
})
But it also does this twice! The output for the "sample.txt" file is:
Optional("Hello world from sample.txt!") Fetching on sample.txt succeed. Optional("Hello world from sample.txt!Hello world from sample.txt!") Fetching on sample.txt succeed.
Why is it calling this twice too? I'm only calling my function once and "start download" is also only printed once.
Update 2: I did some more investigating and found out what's called twice in the contents
function:
It's the whole self.ftpDownload
section!
And inside FTPHelper.ftpLogin the whole self.ftpRetrieve
section is called twice.
And inside FTPHelper.ftpRetrieve the whole self.attributesOfItem
section is called twice.
And probably so on...
ftpProvider?.copyItem
uses the same ftpDownload
func, so at least I know why both contents()
and copyItem()
are affected.
The same question remains though: Why is it calling these functions twice and how do I fix this?
I'm using your library to log into my FTP server and download a file but
func copyItem(path: String, toLocalURL destURL: URL, completionHandler: SimpleCompletionHandler) -> Progress?
(only function for downloading I've found) doesn't support overwriting. So while the first try to download the file to the app's "Documents" folder always succeeds, the second one always fails because the file already exists.My code:
As you can see, I added my own check for already existing files but unfortunately this doesn't help with the second try.
Why is it even trying to download the file twice? Is there maybe some hidden function for downloading that does support overwriting? How can I fix this?