iosobjective-ciphonensstreamnsinputstream

nsoutputstream stuck in status 1(NSStreamStatusOpening = 1) - iOS - objective c


i try to upload an iPod music to ftp server. so using AVAssetExportSession, i make a file at documents folder


exportSession.outputURL = [NSURL fileURLWithPath:musicFilePath];
[exportSession exportAsynchronouslyWithCompletionHandler:^{
    if(exportSession.status == AVAssetExportSessionStatusCompleted) {
        NSLog(@"export completed.");
        self.exportedMusicPath = musicFilePath;
        [self.delegate exportMusicFinish:self.exportedMusicPath];

    }
    else {
        NSLog(@"export failed.");
        [self.delegate exportMusicFinish:@"export failed"];
    }
}];

and I open a nsoutputstream for my ftp upload and get exported file path through delegate


-(void) exportMusicFinish:(NSString *)exportedMusicPath {
    if(!self.fileUpload) {
        self.fileUpload = [[FTPUpload alloc] init];
        self.fileUpload.delegate = self;
    }
    self.exporter = nil;
    [self.fileUpload uploadFileToFTP:exportedMusicPath];
}

self.fileStream = [NSInputStream inputStreamWithFileAtPath:filePath];
assert(self.fileStream != nil);

[self.fileStream open];

// Open a CFFTPStream for the URL.        
self.networkStream = CFBridgingRelease(CFWriteStreamCreateWithFTPURL(NULL, (__bridge CFURLRef) url));
[self.networkStream setProperty:(id)kCFBooleanFalse forKey:(NSString *)kCFStreamPropertyFTPAttemptPersistentConnection];
assert(self.networkStream != nil);

success = [self.networkStream setProperty:@"userid" forKey:(id)kCFStreamPropertyFTPUserName];
assert(success);
success = [self.networkStream setProperty:@"userpw" forKey:(id)kCFStreamPropertyFTPPassword];
assert(success);
//- (BOOL)setProperty:(id)property forKey:(NSString *)key ,object casting needed

self.networkStream.delegate = self;
[self.networkStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
[self.networkStream open];

but my networkstream(nsoutputqtream) stuck in opening status.

my url, path is correct and uploading class work properly to all the files in my documents folder except for this exported files

can anyone help me ? i'm not good at iOS programming...


Solution

  • Core Foundation's FTP support is deprecated for many good reasons. For one, if I'm remembering correctly, it never worked very well. For another, FTP is a horrible way to upload data. It lacks support for resuming uploads, it lacks any security whatsoever (cleartext passwords), runs the risk of never being able to connect if you're behind a NAT-based firewall... basically, FTP is a disaster and a half, and you shouldn't even consider using it in a new app.

    Get yourself a web server, install WebDAV, and use a PUT request. That gives you authentication, TLS (encryption), and native NSURLSession support. It is a much, much better way to solve this problem.