file downloading from ftp server in iOS applicatio

2020-03-06 03:00发布

问题:

can we download a file from a ftp server using iOS sdk's API or by any other way. i know that through http request we can download files from server. so can we download file from ftp server in same way or is there any different sets of API for ftp.

Thanks

回答1:

NSURL *url = [NSURL URLWithString:@"ftp://user:password@host:port/path"];
NSData *data = [[NSData alloc] initWithContentsOfURL:url];

Then you will get the file into data.


SWIFT:

var url = URL(string: "ftp://testUser:testPassword@191.122.0.12:20/ScheduleProject/Database/User.json")  //sudo code: URL(string: "ftp://user:password@host:port/path")
var data: Data? = nil
if let anUrl = url {
    data = Data(contentsOf: anUrl)
}