I am trying to upload a PNG file on FTP server using the following code.
NSURL *ftpURL=[NSURL URLWithString:@"ftp://username:password@localhost"];
NSMutableURLRequest *urlRequest=[[NSMutableURLRequest alloc] initWithURL:ftpURL];
[urlRequest setHTTPMethod:@"POST"];
[postData appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"imageUrl\"; filename=\"dummy.png\"\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
[postData appendData:[@"Content-Type: image/png\r\n" dataUsingEncoding:NSUTF8StringEncoding]];
[postData appendData:[@"Content-Transfer-Encoding: binary\r\n\r\n" dataUsingEncoding:NSUTF8StringEncoding]];
UIImage *img=[UIImage imageNamed:@"a.png"];
NSMutableData *postData=[[NSMutableData alloc] init];
NSData *data=UIImagePNGRepresentation(img);
[postData appendData:data];
[urlRequest setHTTPBody:postData];
[[NSURLConnection alloc] initWithRequest:urlRequest delegate:self startImmediately:YES];
I don’t receive any NSURL connection,like it has failed or ask for Authentication. Only, call back I receive is of
-(void) connectionDidFinishLoading:(NSURLConnection *)connection
I am not sure whether NSURLConnection supports ftp upload. I am not looking to implement it using CFFTPStream. Can any one correct me in my approach?
Your are trying to use FTP and POST in one go, which won’t work in almost any case.
FTP is a complete different protocoll, see for example http://www.faqs.org/rfcs/rfc959.html
It is somewhat more interactive, however many ftp server have a http wrapper which allows easy download, but upload will remain special. So if you want to use it, you should take a library or CFFTPStream.