在 Objective-C iOS 中将内容上传到 FTP [英] Upload things to a FTP in Objective-C iOS
问题描述
几天前,我在询问如何从 FTP 下载文件,然后我解决了 NSData 和 dataWithContentsOfURL 这类问题:
Some days ago I was asking how to download files from a FTP and I solver my problem with NSData and dataWithContentsOfURL of this kind:
ftp://user:pass@server/path/of/file.extension
但是现在我需要上传一个文件,我想知道是否有任何指令可以通过 URL 上传文件,但我认为这是不可能的,而且我看到的许多 iOS 库都使用 PHP,而我没有想要它,Apple 的 SimpleFTPSample 让初级开发人员感到困惑,以至于我什么都不懂,所以一个简单的代码来上传指定 URL、路径、文件、用户和密码的文件?
But now I need to upload a file, and I was wondering if there is any instruction to upload files through an URL but I think it could not be possible and many many libraries I saw for iOS use PHP and I don't want it, and SimpleFTPSample from Apple is so confusing for junior developers that I could not understand nothing, so a simple code to upload a file specifying URL, Path, File, user and pass?
推荐答案
如果你想要一个简单的库,我建议使用 HTTP 和 AFNetworking 库.
If you would like an easy library I would recommend using HTTP and the AFNetworking library.
但是,如果您想做 FTP,Apple 会提供分步说明.它有点毛茸茸,所以我建议根据需要复制和粘贴和调整.您将不得不稍微阅读一下文档.查找上传文件"部分.
However if you want to do FTP, Apple provides step by step instructions. It is a bit hairy, so I recommend just copy and pasting and tweaking as necessary. You will have to read the docs a tiny bit. Look for the "Uploading a File" section.
这应该有助于解决苹果不提供代码的初始部分
This should help with the initial part that apple does not provide the code for
CFStringRef url = CFSTR("ftp://ftp.somedomain.com/file.txt");
CFURLRef requestURL = CFURLCreateWithString(kCFAllocatorDefault, url, NULL);
CFReadStreamRef readStream = CFReadStreamCreateWithFTPURL(kCFAllocatorDefault, requestURL);
希望这会有所帮助.
这篇关于在 Objective-C iOS 中将内容上传到 FTP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!