Hi, I've tried to make a Cocoa application that connects to ftp server. All answers do suggest using connection Kit framework but somehow Im not able to use it. As I compile the framework and add it to my xcode project and build it. Im not able to run the application anymore. I got error in left down corner saying that app exited with status 5.
After solving this one, now I get 9 errors when trying to build: (Heres copy paste)
AppDelegate.m:17: error: 'AbstractConnection' undeclared (first use in this function)
AppDelegate.m:50: error: syntax error before 'AbstractConnection'
AppDelegate.m:55: error: 'baseDirField' undeclared here (not in a function)
AppDelegate.m:56: error: syntax error before 'if'
AppDelegate.m:62: error: syntax error before 'AbstractConnection'
AppDelegate.m:69: error: syntax error before '}' token
AppDelegate.m:71: error: syntax error before 'AbstractConnection'
AppDelegate.m:75: error: syntax error before 'for'
AppDelegate.m:75: error: syntax error before '<' token
when trying to use following code (found with google):
// AppDelegate.h
#import < Cocoa/Cocoa.h >
@protocol AbstractConnectionProtocol;
@interface AppDelegate : NSObject {
IBOutlet NSTextField *hostNameField;
IBOutlet NSTextField *usernameField;
IBOutlet NSTextField *passwordField;
IBOutlet NSTextField *baseDirField;
IBOutlet NSTextView *log;
IBOutlet NSTextField *status;
id <AbstractConnectionProtocol> con;
BOOL isConnected;
}
- (IBAction) connect:(id)sender;
- (IBAction) disConnect:(id)sender;
@end
// AppDelegate.m
#import "AppDelegate.h"
#import < Connection/Connection.h >
@implementation AppDelegate
- (IBAction) connect:(id)sender;
{
NSError *err = nil;
con = [[AbstractConnection connectionToHost:[hostNameField stringValue]
port:@"21"
username:[usernameField stringValue]
password:[passwordField stringValue]
error:&err] retain];
if (!con)
{
if (err)
{
[NSApp presentError:err];
}
return;
}
NSTextStorage *textStorage = [log textStorage];
[textStorage setDelegate:self]; // get notified when text changes
[con setTranscript:textStorage];
[con setDelegate:self];
[status setStringValue:[NSString stringWithFormat:@"Connecting to: %@", [hostNameField stringValue]]];
[con connect];
}
- (IBAction) disConnect:(id)sender;
{
if( con )
{
[con disconnect];
}
}
- (void)connection:(AbstractConnection *)aConn didConnectToHost:(NSString *)host
{
isConnected = YES;
[status setStringValue:[NSString stringWithFormat:@"Connected to: %@", host]];
NSString *dir = [[baseDirField stringValue] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
if (dir && [dir length] > 0)
[con changeToDirectory:[baseDirField stringValue]];
[con directoryContents];
}
- (void)connection:(AbstractConnection *)aConn didDisconnectFromHost:(NSString *)host
{
isConnected = NO;
[status setStringValue:[NSString stringWithFormat:@"Disconnected from: %@", host]];
[con release];
con = nil;
}
- (void)connection:(AbstractConnection *)aConn didReceiveContents:(NSArray *)contents ofDirectory:(NSString *)dirPath
{
NSLog(@"%@ %@", NSStringFromSelector(_cmd), dirPath);
int i = 0;
for (i=0; i < [contents count]; ++i) {
id object = [contents objectAtIndex:i];
[[[log textStorage] mutableString] appendFormat:@"%@\n", object];
}
}
@end
So I would like to know what Im doing wrong.