Cocoa Read NSInputStream from FTP connection
Posted
by Chuck
on Stack Overflow
See other posts from Stack Overflow
or by Chuck
Published on 2010-04-06T10:17:32Z
Indexed on
2010/04/06
10:23 UTC
Read the original article
Hit count: 475
Hi,
I (apparently) manage to make a ftp connection, but fail to read anything from it, and with good cause: I don't reach the reading until the connection has timed out.
Here's my code:
NSHost *host = [NSHost hostWithAddress:@"127.0.0.1"];
[NSStream getStreamsToHost:host port:3333 inputStream:&iStream outputStream:&oStream];
NSMutableDictionary *settings = [NSMutableDictionary dictionaryWithCapacity:1];
[settings setObject:(NSString *)NSStreamSocketSecurityLevelTLSv1 forKey:(NSString *)kCFStreamSSLLevel];
[settings setObject:[NSNumber numberWithBool:YES] forKey:(NSString *)kCFStreamSSLAllowsAnyRoot];
[iStream retain];
[iStream setDelegate:self];
[iStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
CFReadStreamSetProperty((CFReadStreamRef)iStream, kCFStreamPropertySSLSettings, (CFTypeRef)settings);forKey:NSStreamSocketSecurityLevelKey];
[iStream open];
[oStream retain];
[oStream setDelegate:self];
[oStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
CFWriteStreamSetProperty((CFWriteStreamRef)oStream, kCFStreamPropertySSLSettings, (CFTypeRef)settings);
forKey:NSStreamSocketSecurityLevelKey];
[oStream open];
NSMutableData *returnMessage = [NSMutableData dataWithLength: 300];
[iStream read: [returnMessage mutableBytes] maxLength: 300];
NSString *readData = [[NSString alloc] initWithBytes: [returnMessage bytes] length: 300 encoding: NSUTF8StringEncoding];
NSRunAlertPanel(@"response", readData, nil, nil, nil);
I have not sent a request to the FTP to switch to ssl yet.
Any help is greatly appreciated as I find Xcode quite horrible for debugging (no exception or error msg on failed steps what so ever).
- Chuck
© Stack Overflow or respective owner