1

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?

Inder Kumar Rathore
  • 39,458
  • 17
  • 135
  • 184
Alejandro L.
  • 1,066
  • 5
  • 17
  • 38

3 Answers3

5

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.

Ben Coffman
  • 1,750
  • 1
  • 18
  • 26
  • With CFSTR cannot make a dynamic string, right? I cannot `CFSTR(path)` just with literal strings? – Alejandro L. Jan 24 '13 at 10:19
  • 1
    CFString is “toll-free bridged” with its Cocoa Foundation counterpart, NSString...which means you can create the string dynamically with NSString (assuming you are more familiar with it) and then assign it like so: CFStringRef url = (__bridge CFStringRef)(SOME_NSString) – Ben Coffman Jan 24 '13 at 12:40
5

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.

miho
  • 11,765
  • 7
  • 42
  • 85
3

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

rmaddy
  • 314,917
  • 42
  • 532
  • 579