通过ftp发送字符串:获取错误

时间:2011-06-20 02:31:02

标签: iphone ftp nsstring

我正在尝试使用下面的代码通过ftp发送一个字符串,但是我收到一个错误:

{

    //miscellaneous lines of code.....
    //Convert contents of shopping cart into a property list
    [Cart serializeCart];

    //now need to transport the propertyList to the webserver
    //first step is get the serialized propertylist from the documents folder
    NSString *pathToSerializedCart = [rootPath stringByAppendingPathComponent:@"serializedCart.plist"];

    NSString *shoppingCartString;

   if (![fileManager fileExistsAtPath:pathToSerializedCart])
   {
       NSLog(@"ERROR:\nCouldnt find serialized cart in documents folder.");
   }
   else 
   {
       NSData *serializedData = [NSData            dataWithContentsOfFile:pathToSerializedCart];
       shoppingCartString = [[NSString alloc] initWithData:serializedData encoding:NSUTF8StringEncoding];
   }

   NSLog(@"%@", shoppingCartString);
   //Now that the cart is converted into a string. it is ready for transport
   NSURL *url = [NSURL URLWithString:@"ftp://username:password@domainName.com/folder/serializedCart.xml"];

   BOOL OK =[shoppingCartString writeToURL:url atomically:NO encoding:NSUTF8StringEncoding error:&error];   
   if(!OK) {
       NSLog(@"Error writing to file %@ , error = %@", url, [error localizedFailureReason]);
   }

我正在为此代码获取以下控制台输出:

Error writing to file ftp://username:password@domainName.com/folder/serializedCart.xml , error = (null)

其中一个变量:_domain在最后一行的这个错误对象中,我在调试过程中将鼠标移到它上面说NSCocoaErrorDomain

我不确定如何调试它。 有人可以提出任何建议吗?

1 个答案:

答案 0 :(得分:0)

writeToURL:..方法不支持FTP协议。您必须使用其他机制将字符串内容写入ftp服务器。您可以查看ios-ftp-server等工具来处理此类上传。您还可以从Apple查看此sample code