views:

723

answers:

5

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.

+1  A: 

Are you sure that <Connection/Connection.h> is importing everything you need (specifically the file that defines AbstractConnection)?

Dave DeLong
+1  A: 
#import < Connection/Connection.h >

Try removing those spaces. It's unlikely that you have a framework named “ Connection” with a header file named “Connection.h ” in it.

Peter Hosey
A: 

I am having exactly the same problem with ConnectionKit :(

It seems that the Framework is brokem in a fundamental way as even the unit tests will not compile and the example application that is noted in the docs doesn't either.

If anyone could do us a favour and try to compile this framework from the trunk or the 1.2.2 branch it would be greatly appreciated.

And then please explain how you did it

TIA

Kieren
A: 

I don't know which version you use, but at least in 1.2.2 connections conform to the protocol CKAbstractConnection, not AbstractConnectionProtocol. I think the code you found with Google is not for any current version of Connection Kit.

BTW, for me the 1.2 branch currently seems to work the best. And yes, the lack of sample code that compiles and documentation can be quite frustrating whilst working with this framework.

Johan Kool
A: 

Has anyone really been able to use this framework successfully??

There's been claims by some that they have, but from my own experience, it is crashy, crashy, crashy. Any questions always seem to go unanswered.

To boot, there's absolutely no documentation of any kind, and whatever example are severely outdated.

Abe