Search code examples
iphoneiosipadftpios5

file downloading from ftp server in iOS application


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


Solution

  • 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)
    }