【问题标题】:Sending string via ftp : getting error通过 ftp 发送字符串:出现错误
【发布时间】:2011-06-20 02:31:01
【问题描述】:

我正在尝试使用以下代码通过 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

我不确定如何调试它。 有人可以给点建议吗?

【问题讨论】:

    标签: iphone ftp nsstring


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 2015-12-25
      • 2015-04-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-11-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多