Open Stream Error in SimpleFTPSample presented in Apple documentation

I want to upload images to the server via ftp.

I found SimpleFTPSample in the documentation for Apple and downloaded it.

When running the application (I am using xcode 4.5.2, the target simulator of iphone 5.0) it works fine. I try to create a directory on my server through this application and succeed.

But when loading the image presented in the application, an “open stream error” will occur. I did not make any changes to the application. Just enter url, username and password. I think there is no problem with this, since the directory that I specified was created successfully.

When creating the directory, the URL "ftp://54.xyz/newfolder/" is created successfully.

But when loading the URL is "ftp://54.xyz/TestImage1.png"

file path - "/var/folders/pn/8p0jc4qn70v37j58c1kwf8l80000gn/T/TestImage1.png"

The url is obtained by adding the last line of the component with the ftp url I specified.

So what is the mistake?

In fn,

- (void)stream:(NSStream *)aStream handleEvent:(NSStreamEvent)eventCode { case NSStreamEventErrorOccurred: { [self stopSendWithStatus:@"Stream open error"]; } break; 

an error message is opened and displayed.

I googled all day and no necessary results. This is very urgent, and I can’t even start generosity for it. Please, help

+3
source share
3 answers

Try it....

  - (void)sendDidStart { // self.statusLabel.text = @"Sending"; [[NetworkManager sharedInstance] didStartNetworkOperation]; } - (void)updateStatus:(NSString *)statusString { assert(statusString != nil); //self.statusLabel.text = statusString; } - (void)sendDidStopWithStatus:(NSString *)statusString { if (statusString == nil) { statusString = @"Put succeeded"; } [[NetworkManager sharedInstance] didStopNetworkOperation]; } #pragma mark * Core transfer code // This is the code that actually does the networking. // Because buffer is declared as an array, you have to use a custom getter. // A synthesised getter doesn't compile. - (uint8_t *)buffer { return self->_buffer; } - (BOOL)isSending { return (self.networkStream != nil); } - (void)startSend:(NSString *)filePath { BOOL success; NSURL * url; NSLog(@"localFilePathforImage..:%@",localFilePathforImage); assert(localFilePathforImage != nil); assert([[NSFileManager defaultManager] fileExistsAtPath:localFilePathforImage]); assert( [localFilePathforImage.pathExtension isEqual:@"png"] || [localFilePathforImage.pathExtension isEqual:@"jpg"] ); assert(self.networkStream == nil); // don't tap send twice in a row! assert(self.fileStream == nil); // ditto // First get and check the URL. url = [[NetworkManager sharedInstance] smartURLForString:@"ftp://80.544/"]; success = (url != nil); if (success) { // Add the last part of the file name to the end of the URL to form the final // URL that we're going to put to. url = CFBridgingRelease( CFURLCreateCopyAppendingPathComponent(NULL, ( CFURLRef) url, ( CFStringRef) imageString , false) ); success = (url != nil); } // If the URL is bogus, let the user know. Otherwise kick off the connection. if ( ! success) { // self.statusLabel.text = @"Invalid URL"; } else { // Open a stream for the file we're going to send. We do not open this stream; // NSURLConnection will do it for us. self.fileStream = [NSInputStream inputStreamWithFileAtPath:localFilePathforImage]; assert(self.fileStream != nil); [self.fileStream open]; // Open a CFFTPStream for the URL. self.networkStream = CFBridgingRelease( CFWriteStreamCreateWithFTPURL(NULL, ( CFURLRef) url) ); assert(self.networkStream != nil); // if ([self.usernameText.text length] != 0) { success = [self.networkStream setProperty:@"yourusername" forKey:(id)kCFStreamPropertyFTPUserName]; assert(success); success = [self.networkStream setProperty:@"password" forKey:(id)kCFStreamPropertyFTPPassword]; assert(success); //} self.networkStream.delegate = self; [self.networkStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode]; [self.networkStream open]; // Tell the UI we're sending. [self sendDidStart]; } } - (void)stopSendWithStatus:(NSString *)statusString { if (self.networkStream != nil) { [self.networkStream removeFromRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode]; self.networkStream.delegate = nil; [self.networkStream close]; self.networkStream = nil; } if (self.fileStream != nil) { [self.fileStream close]; self.fileStream = nil; } [self sendDidStopWithStatus:statusString]; } - (void)stream:(NSStream *)aStream handleEvent:(NSStreamEvent)eventCode // An NSStream delegate callback that called when events happen on our // network stream. { #pragma unused(aStream) assert(aStream == self.networkStream); switch (eventCode) { case NSStreamEventOpenCompleted: { [self updateStatus:@"Opened connection"]; } break; case NSStreamEventHasBytesAvailable: { assert(NO); // should never happen for the output stream } break; case NSStreamEventHasSpaceAvailable: { [self updateStatus:@"Sending"]; // If we don't have any data buffered, go read the next chunk of data. if (self.bufferOffset == self.bufferLimit) { NSInteger bytesRead; bytesRead = [self.fileStream read:self.buffer maxLength:sSendBufferSize]; if (bytesRead == -1) { [self stopSendWithStatus:@"File read error"]; } else if (bytesRead == 0) { [self stopSendWithStatus:nil]; } else { self.bufferOffset = 0; self.bufferLimit = bytesRead; } } // If we're not out of data completely, send the next chunk. if (self.bufferOffset != self.bufferLimit) { NSInteger bytesWritten; bytesWritten = [self.networkStream write:&self.buffer[self.bufferOffset] maxLength:self.bufferLimit - self.bufferOffset]; assert(bytesWritten != 0); if (bytesWritten == -1) { [self stopSendWithStatus:@"Network write error"]; } else { self.bufferOffset += bytesWritten; } } } break; case NSStreamEventErrorOccurred: { [self stopSendWithStatus:@"Stream open error"]; } break; case NSStreamEventEndEncountered: { // ignore } break; default: { assert(NO); } break; } } 
+2
source

I have the same problem.

This is for the hosting provider. I think the problem is that the code may be confused by the "@" sign in the login name = dev@atoz.com. ?

Are you using username with @sing?

+1
source

Adding this line before setting the networkStream delegate to PutController.m StartSend fixed the problem for me:

 [self.networkStream setProperty:(id)kCFBooleanFalse forKey:(id)kCFStreamPropertyFTPUsePassiveMode]; 

Without the above line (or with the property set to kCFBooleanTrue instead of kCFBooleanFalse), I received the Stream Open error message in sequence. I only tried with one FTP server, but it does not seem to support passive mode, which is apparently the default.

+1
source

All Articles