我是 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];
}
}