在FTP上上传多个文件 [英] Upload more than one file on FTP
问题描述
我是新来的objective-c和iOS。我正在使用SimpleFTPSample来制作上传和下载文件到ftp的测试应用程序。我需要上传两个ftp文件,但在SimpleFTPSample中只能上传一个...所以我需要添加到源代码中?我猜一定有一些循环,但我不知道在哪里...
这是我的代码,我为()添加,但我知道这是错误的,但我没有任何想法。感谢您的帮助。
success =(url!= nil);
NSMutableArray * listFile = [[NSMutableArray alloc] initWithCapacity:2];
[listFile addObject:[[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@1.txt]];
[listFile addObject:[[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@2.txt]];
for(int i = 0; i <= 1; i ++){
self.filePath = [listFile objectAtIndex:i];
url = [NSURL URLWithString:@ftp:// anonymous @ ftp];
$ b $ url = CFBridgingRelease(
CFURLCreateCopyAppendingPathComponent(NULL,(__bridge CFURLRef)url,(__bridge CFStringRef)[self.filePath lastPathComponent],false));
//);
success =(url!= nil);
self.ftpFileStream = [NSInputStream inputStreamWithFileAtPath:_filePath];
assert(self.ftpFileStream!= nil);
[self.ftpFileStream open];
self.ftpNetworkStream = CFBridgingRelease(
CFWriteStreamCreateWithFTPURL(NULL,(__bridge CFURLRef)url)
);
assert(self.ftpNetworkStream!= nil);
self.ftpNetworkStream.delegate = self;
[self.ftpNetworkStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
[self.ftpNetworkStream open];
$ b
另一种选择是
2) ASIHTTPRequest's ASINetworkQueue
注意:ASIHTTPRequest不再维护......开心编码:)
i'm new to objective-c and iOS. I'm using SimpleFTPSample to make test app for uploading and downloading files to ftp. I need to upload two files on ftp, but in SimpleFTPSample you could upload only one... so what do i need add to source code? I guess there must be some loop, but i don't know where...
Here's my code, i add for() but i know that is wrong, but i do not have any ideas. Thanks for any help.
success = (url != nil);
NSMutableArray *listFile = [[NSMutableArray alloc] initWithCapacity:2];
[listFile addObject:[[[NSBundle mainBundle]resourcePath]stringByAppendingPathComponent:@"1.txt"]];
[listFile addObject:[[[NSBundle mainBundle]resourcePath]stringByAppendingPathComponent:@"2.txt"]];
for (int i= 0; i <= 1; i++ ) {
self.filePath = [listFile objectAtIndex:i];
url = [NSURL URLWithString:@"ftp://anonymous@ftp"];
url = CFBridgingRelease(
CFURLCreateCopyAppendingPathComponent(NULL, (__bridge CFURLRef) url, (__bridge CFStringRef) [self.filePath lastPathComponent], false));
// );
success = (url != nil);
self.ftpFileStream = [NSInputStream inputStreamWithFileAtPath:_filePath];
assert(self.ftpFileStream != nil);
[self.ftpFileStream open];
self.ftpNetworkStream = CFBridgingRelease(
CFWriteStreamCreateWithFTPURL(NULL, (__bridge CFURLRef) url)
);
assert(self.ftpNetworkStream != nil);
self.ftpNetworkStream.delegate = self;
[self.ftpNetworkStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
[self.ftpNetworkStream open];
}
}
I believe you can do the uploading of multiple files task in other efficient ways.
1) Using AFNetworking
and the other option is
2) ASIHTTPRequest's ASINetworkQueue
NOTE: ASIHTTPRequest is no longer maintained...happy coding:)
这篇关于在FTP上上传多个文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!