Cocoa NSStream TCP connection to FTP

Posted by Chuck on Stack Overflow See other posts from Stack Overflow or by Chuck
Published on 2010-04-05T16:05:52Z Indexed on 2010/04/05 16:33 UTC
Read the original article Hit count: 511

Filed under:
|
|
|
|

Hi,

I'm new to Cocoa, but not to programming. Recently I decided I wanted to write a FTP client for Mac, and so I first made it in the language I'm most comfortable in (on Windows), and then moved on to Cocoa when I had the workings of FTP communications down.

My question is (apparently) a bit controversial: How do I establish a read/writeable connection to (a ftp server)?

What I have so far (non working obviously):

NSInputStream *iStream;
NSOutputStream *oStream;
NSHost *host = [NSHost hostWithAddress:@"127.0.0.1"];
[NSStream getStreamsToHost:host port:3333 inputStream:&iStream outputStream:&oStream];
// ftp port: 3333
[iStream retain];
[oStream retain];
[iStream scheduleInRunLoop:[NSRunLoop currentRunLoop]
             forMode:NSDefaultRunLoopMode];
[oStream scheduleInRunLoop:[NSRunLoop currentRunLoop]
             forMode:NSDefaultRunLoopMode];
[iStream setDelegate:self];
[oStream setDelegate:self]; // which is not implemented apparently
[iStream open];
[oStream open];
// .... [iStream write: (const uint8_t *)buf maxLength:8];

Which is partially based on http://developer.apple.com/mac/library/documentation/cocoa/Conceptual/Streams/Articles/NetworkStreams.html Now, why have I chosen NSStream? Because while this question is merely about how to connect to a FTP stream, my whole project will also include SSL and as far as I've been able to search here and on google, NSStream is capable of "switching" to a SSL connection.

I've not been able to see the connection being made (which I'm usually able to do), but I also heard something about having to write to the stream before the stream will open?

Any pointers are greatly appreciated, and sorry if my question is annoying - I'm new to Cocoa :)

© Stack Overflow or respective owner

Related posts about cocoa

Related posts about ftp