Upload more than one file on FTP

2019-07-20 15:07发布

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

    }

}

1条回答
ゆ 、 Hurt°
2楼-- · 2019-07-20 15:41

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:)

查看更多
登录 后发表回答