FileProvider
FileProvider copied to clipboard
Trying to connect to FTP gives error 1011
Hello,
i have to connect to a local ftp server but .isReachable tells me, that "Task could not completed" with error 1011 (Bad Server Response).
Optional(Error Domain=NSURLErrorDomain Code=-1011 "(null)" UserInfo={NSURL=ftp://192.168.21.3:21/, NSErrorFailingURLKey=ftp://192.168.21.3:21/, NSErrorFailingURLStringKey=ftp://192.168.21.3:21/})
This only occurs with this single server. Read/Write from two different Webserver is working properly.
`class FTPUploadRequest: NSObject {
static let defaultHostname = Config.ftp["hostname"] ?? ""
static let defaultUsername = Config.ftp["user"] ?? ""
static let defaultPassword = Config.ftp["password"] ?? ""
static let defaultPath = Config.ftp["path"] ?? ""
var provider: FTPFileProvider?
var dataToSend: Data?
var file: String?
init(file: String, path: String = FTPUploadRequest.defaultPath, dataToSend: Data, hostname: String = FTPUploadRequest.defaultHostname, username: String = FTPUploadRequest.defaultUsername, password: String = FTPUploadRequest.defaultPassword) {
self.dataToSend = dataToSend
super.init()
let credential = URLCredential(user: username, password: password, persistence: .none)
if let url = URL(string: "ftp://\(hostname):21/") {
provider = FTPFileProvider(baseURL: url, mode: .extendedPassive, credential: credential)
print(url)
}
self.file = file
provider?.delegate = self
}
func start(completion: @escaping ((Error?) -> ())) {
let path = "\(FTPUploadRequest.defaultPath)\(file ?? "LMDATEI")"
print(path)
if let provider = provider {
provider.isReachable { reachable, error in
if reachable {
print("ftp is reachable!")
provider.writeContents(path: path, contents: self.dataToSend, atomically: true, overwrite: false, completionHandler: completion)
} else {
print(error)
print(error?.localizedDescription)
// completion(error)
}
}
}
}
}`
Have you been able to fix this yet? So far I've tested it with 4 ftp servers:
- Server I set up on my other PC: ftp://10.1.1.210
- Something like (changed name but actually exists!): ftp://ftp.mydomain.com
- Tele2's test server: ftp://speedtest.tele2.net
- Other test server: ftp://test.rebex.net
I get the same error message for all of them, even though it actually lets connects to the server BUT I can't access files on the second server, "contentsOfDirectory" always returns an empty array. Everything's fine with the other 3 servers server - can search folders and download/upload files.