0

I have tried this:

NSURL *url = [NSURL URLWithString:ftpURL];    
NSData *data = [NSData dataWithContentsOfURL:url];            
if (data){
   [data writeToFile:dataPath atomically:(YES)];
}

But it doesn't seem to work... I have initialised dataPath, and ftpURL elsewhere..I know they aren't null. And data just returns null for some odd reason.

Does the above method support FTP download?

I have also searched on Google and StackOverflow regarding this and I couldn't find a solution that would help me. I saw SimpleFTPSample and I thought the above method was easier.

user959631
  • 1,004
  • 2
  • 14
  • 34
  • Have you tried using dataWithContentsOfURL:options:error: and looking at the NSError return? – mjswan Oct 07 '13 at 21:51
  • @neilco I thought upload and download where different? – user959631 Oct 07 '13 at 21:52
  • @mjswan No, let me try that... Thanks – user959631 Oct 07 '13 at 21:53
  • @user959631 The [first answer](http://stackoverflow.com/a/14484610/24073) shows how to download via FTP. – neilco Oct 07 '13 at 21:58
  • Turns out that my `url` is returning null too. I checked `ftpUrl` and that definitely isn't null. Weird. – user959631 Oct 07 '13 at 22:07
  • @neilco Wow, I completely missed that. God I am so tired. Sorry for that =] – user959631 Oct 07 '13 at 22:08
  • Ok, so how would I write the `readStream` to file? `CFStringRef url = CFSTR("ftp://ftp.somedomain.com/file.txt"); CFURLRef requestURL = CFURLCreateWithString(kCFAllocatorDefault, url, NULL); CFReadStreamRef readStream = CFReadStreamCreateWithFTPURL(kCFAllocatorDefault, requestURL);` – user959631 Oct 07 '13 at 22:18

1 Answers1

0

Ok, I found out my problem, NSURL was returning null because I needed to stringByAddingPercentEscapesUsingEncoding my ftpURL string.

Thanks guys for the help anyway =]

user959631
  • 1,004
  • 2
  • 14
  • 34