在Objective-C iOS上将东西上传到FTP [英] Upload things to a FTP in Objective-C iOS
问题描述
ftp:// user:pass@server/path/of/file.extension
但现在我需要上传一个文件,而我想知道是否有任何指令通过URL上传文件,但我认为这是不可能的,许多我看到iOS的库使用PHP,我不想要它,而Apple的SimpleFTPSample对于初级开发人员来说是如此令人困惑我什么都不懂,所以上传一个简单的代码来指定URL,路径,文件,用户和密码?如果你想要一个简单的库,我会推荐使用HTTP和AFNetworking库。
然而,如果你想做FTP,Apple提供了一步一步的指导。这有点多毛,所以我建议只是复制和粘贴,并根据需要调整。你将不得不阅读文件一点点。查找上传文件部分。
这应该有助于苹果不提供代码的初始部分
CFStringRef url = CFSTR(ftp://ftp.somedomain.com/file.txt);
CFURLRef requestURL = CFURLCreateWithString(kCFAllocatorDefault,url,NULL);
CFReadStreamRef readStream = CFReadStreamCreateWithFTPURL(kCFAllocatorDefault,requestURL);
希望这会有所帮助。
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
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?
If you would like an easy library I would recommend using HTTP and the AFNetworking library.
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);
Hope this helps.
这篇关于在Objective-C iOS上将东西上传到FTP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!