通过ftp发送字符串:出错 [英] Sending string via ftp : getting error

查看:107
本文介绍了通过ftp发送字符串:出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

  { 

//其他行代码.....
//将购物车的内容转换为属性列表
[Cart serializeCart];

//现在需要将propertyList传输到web服务器
//第一步是从文档文件夹获取序列化的属性列表
NSString * pathToSerializedCart = [rootPath stringByAppendingPathComponent:@ serializedCart.plist];

NSString * shoppingCartString;如果(![fileManager fileExistsAtPath:pathToSerializedCart])
{
NSLog(@ERROR:\\\
Couldnt在文档文件夹中查找序列化购物车。);


}
else
{
NSData * serializedData = [NSData dataWithContentsOfFile:pathToSerializedCart];
shoppingCartString = [[NSString alloc] initWithData:serializedData encoding:NSUTF8StringEncoding];
}

NSLog(@%@,shoppingCartString);
//现在将购物车转换为字符串。它准备运输
NSURL * url = [NSURL URLWithString:@ftp:// username:password@domainName.com/folder/serializedCart.xml];

OOL OK = [shoppingCartString writeToURL:url atomically:NO encoding:NSUTF8StringEncoding error:& error];
if(!OK){
NSLog(@错误写入文件%@,错误=%@,url,[error localizedFailureReason]);
}

我得到了下面的代码输出:

 写入文件的错误ftp://用户名:password@domainName.com/folder/serializedCart.xml,error =(null)

其中一个变量: _domain 最后一行的时候,我在调试期间将鼠标悬停在它上面说 NSCocoaErrorDomain



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

解决方案

writeToURL:.. 方法不支持 FTP 协议。您将不得不使用其他机制将字符串内容写入ftp服务器。您可以查看诸如 ios-ftp-server 来处理这种上传。您还可以查看 示例代码 来自Apple。


I'm trying to send a string via ftp using the code below but I'm getting an error:

{

    //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]);
   }

I'm getting the following console output for this code:

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

One of the variables: _domain in this error object in the last line when, I mouse over it during debugging says NSCocoaErrorDomain

I'm not sure how to debug this. Could someone give any suggestions?

解决方案

The writeToURL:.. methods don't support the FTP protocol. You'll have to use other mechanisms to write the string content onto an ftp server. You can look at tools such as ios-ftp-server to handle such uploads. You can also look at this sample code from Apple.

这篇关于通过ftp发送字符串:出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆