Upload things to a FTP in Objective-C iOS

2019-01-26 01:08发布

问题:

Some days ago I was asking how to download files from a FTP and I solver my problem with NSData and dataWithContentsOfURL of this kind:

ftp://user:pass@server/path/of/file.extension

But now I need to upload a file, and I was wondering if there is any instruction to upload files through an URL but I think it could not be possible and many many libraries I saw for iOS use PHP and I don't want it, and SimpleFTPSample from Apple is so confusing for junior developers that I could not understand nothing, so a simple code to upload a file specifying URL, Path, File, user and pass?

回答1:

If you would like an easy library I would recommend using HTTP and the AFNetworking library.

However if you want to do FTP, Apple provides step by step instructions. It is a bit hairy, so I recommend just copy and pasting and tweaking as necessary. You will have to read the docs a tiny bit. Look for the "Uploading a File" section.

http://developer.apple.com/library/ios/#documentation/Networking/Conceptual/CFNetwork/CFFTPTasks/CFFTPTasks.html

This should help with the initial part that apple does not provide the code for

CFStringRef url = CFSTR("ftp://ftp.somedomain.com/file.txt");
CFURLRef requestURL = CFURLCreateWithString(kCFAllocatorDefault, url, NULL);

CFReadStreamRef readStream = CFReadStreamCreateWithFTPURL(kCFAllocatorDefault, requestURL);

Hope this helps.



回答2:

Take a look at Apple Simple FTP Sample. All you need is there.

If you are looking for a Framework have a look at the ConnectionKit project.



回答3:

BlackRaccoon is a good, free, open source library for doing FTP transfers.