Iphone 使用AFNetworking将刚刚在UIIMagepickercontroller中拍摄的图像上载到FTP服务器

Iphone 使用AFNetworking将刚刚在UIIMagepickercontroller中拍摄的图像上载到FTP服务器,iphone,ios,object,uiimagepickercontroller,afnetworking,Iphone,Ios,Object,Uiimagepickercontroller,Afnetworking,我尝试使用AFNetworking将刚刚在UIImagePickerController中拍摄的图像上载到FTP服务器,我使用了以下代码: url = [NSURL URLWithString:@"ftp://user:pass@server"]; NSUserDefaults *def = [NSUserDefaults standardUserDefaults]; AFHTTPClient *httpClient = [[AFHTTPClient alloc] initWithBa

我尝试使用AFNetworking将刚刚在UIImagePickerController中拍摄的图像上载到FTP服务器,我使用了以下代码:

url = [NSURL URLWithString:@"ftp://user:pass@server"];
NSUserDefaults *def = [NSUserDefaults standardUserDefaults];

    AFHTTPClient *httpClient = [[AFHTTPClient alloc] initWithBaseURL:url];

    UIImage *imageIWantToUpload = imageupload;
    NSData *dataToUpload = UIImageJPEGRepresentation(imageIWantToUpload, 0.5);


    // Create the NSData object for the upload process

    NSMutableURLRequest *myRequest = [httpClient multipartFormRequestWithMethod:@"POST" path:@"upload.php"
    parameters:nil constructingBodyWithBlock: ^(id <AFMultipartFormData>formData) {
                                                                     [formData appendPartWithFileData:dataToUpload name:@"uploadedfile" fileName:[NSString stringWithFormat:@"%@.jpg",[def valueForKey:@"cUsuario"]] mimeType:@"images/jpeg"];
                                                                 }];

    AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:myRequest];
    [operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
        NSLog(@"success: %@", operation.responseString);
    }
    failure:^(AFHTTPRequestOperation *operation, NSError *error) {
    // If access token is null , we ask to the user if he wants to sign in or sign up ???
    NSLog(@"error: %@",  operation.responseString);
    }
     ];
    [operation setUploadProgressBlock:^(NSUInteger bytesWritten, long long totalBytesWritten, long long totalBytesExpectedToWrite) {
        NSLog(@"Sent %lld of %lld bytes", totalBytesWritten, totalBytesExpectedToWrite);
    }];
    NSOperationQueue *queue = [[[NSOperationQueue alloc] init] autorelease];
    [queue addOperation:operation];
url=[NSURL URLWithString:@”ftp://user:pass@服务器“];
NSUserDefaults*def=[NSUserDefaults standardUserDefaults];
AFHTTPClient*httpClient=[[AFHTTPClient alloc]initWithBaseURL:url];
UIImage*imageIWantToUpload=imageupload;
NSData*dataToUpload=UIImageJPEG表示法(imageIWantToUpload,0.5);
//为上载过程创建NSData对象
NSMutableURLRequest*myRequest=[httpClient multipartFormRequestWithMethod:@“POST”路径:@“upload.php”
参数:nil constructingBodyWithBlock:^(id formData){
[formData appendPartWithFileData:DataToUploadName:@“uploadedfile”文件名:[NSString stringWithFormat:@“%@.jpg”,[def valueForKey:@“cUsuario”]]mimeType:@“images/jpeg”];
}];
AFHTTPRequestOperation*操作=[[AFHTTPRequestOperation alloc]initWithRequest:myRequest];
[操作setCompletionBlockWithSuccess:^(AFHTTPRequestOperation*操作,id响应对象){
NSLog(@“成功:%@”,操作。响应日志);
}
失败:^(AFHTTPRequestOperation*操作,NSError*错误){
//如果访问令牌为空,我们会询问用户是否要登录或注册???
NSLog(@“错误:%@”,操作。响应字符串);
}
];
[操作设置LoadProgressBlock:^(NSUTEGER字节写入、long long TotalBytesWrite、long long totalBytesExpectedToWrite){
NSLog(@“已发送%lld个字节,共%lld个字节”,TotalBytesWrite,totalBytesExpectedToWrite);
}];
NSOperationQueue*队列=[[[NSOperationQueue alloc]init]autorelease];
[队列添加操作:操作];
在服务器端:file upload.php

<?php
$filename="uploaded";
$target_path = "uploads/";

$target_path = $target_path . basename( $_FILES['uploadedfile']['name']); 

if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
    echo "The file ".  basename( $_FILES['uploadedfile']['name']). 
    " has been uploaded";
} else{
    echo "There was an error uploading the file, please try again!";
}
?%gt;

因此您可以通过http协议将文件上载到ftp服务器?在您的情况下,您可以修改要上载的url
url=[NSURL URLWithString:@”http://server/file_upload.php“]
我的服务器可以使用FTP帐户上载文件。所以我设置的url是@adali我知道你有一个ftp服务器,但你不能通过http使用它,你的ftp服务器怎么知道运行你的文件_upload.php?