iphone - 在 FTP 上上传多个文件

标签 iphone ios objective-c xcode ftp

我是 Objective-C 和 iOS 的新手。我正在使用 SimpleFTPSample 制作用于将文件上传和下载到 ftp 的测试应用程序。我需要在 ftp 上上传两个文件,但在 SimpleFTPSample 中只能上传一个...那么我需要在源代码中添加什么?我想一定有一些循环,但我不知道在哪里......

这是我的代码,我添加了 for() 但我知道这是错误的,但我没有任何想法。感谢您的帮助。

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];

    }

}

最佳答案

我相信您可以通过其他有效的方式完成多个文件的上传任务。

1) 使用AFNetworking

另一个选项是

2) ASIHTTPRequest's ASI网络队列

注意:ASIHTTPRequest 不再维护...编码愉快:)

关于iphone - 在 FTP 上上传多个文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14455276/

相关文章:

javascript - 无法重现 TypeError : 'undefined' is not an object

iphone - 为什么 Xcode 引用不存在的文件?

iphone - 使用 AQ 和音频文件流动态检测和流式传输 AAC

ios - AVCaptureDevice videoZoomFactor 捏合缩放率

ios - 如何在 IOS 中使用 FB SDK 创建 Facebook 应用广告

iphone - 在 ScrollView 崩溃时需要帮助

ios - MCSessionDelegate 要求类符合 NSObjectProtocol

iphone - JSON 子级提取 - 如何? Objective-C

ios - 将选定的项目值快速传递给新的 View Controller

iphone - 在多个矩形中绘制一个 NSString