Archived Forum Post

Index of archived forum posts

Question:

Xcode Cocoa FTP application with progress monitoring

Aug 22 '12 at 05:56

Hello,

I have to develop an application in Xcode. I started to work with it for a short time so I'm beginner. My code is based on the CK examle codes, but I couldn't figure out how to use a progressbar during an FTP or SFTP upload.

Is there any way to get a small example code with S/FTP + progressbar support?

Thank you!


Answer

The pattern for implementing event callbacks is the same for all Chilkat classes that support it.

Your app would define and implement a class that inherits from one of the CkoProgress base classes. You provide method implementations to override the methods specified in the CkoProgress classes (see the header files). The callback object is specified via the EventCallbackObject property.

For example, to setup FTP2 event callbacks for AbortCheck, PercentDone, and BeginDownloadFile, you would create a class that inherits from CkoFtp2Progress. In this example, your application's event callback class is named MyFtpProgress. Here are snippets for the MyFtpProgress header and implementation that should make it clear:


MyFtpProgress.h:

    @interface MyFtpProgress : CkoFtp2Progress {

}

- (id)init;
- (void)dealloc;
- (void)dispose;

- (void)AbortCheck: (BOOL *)abort;
- (void)PercentDone: (NSNumber *)pctDone
              abort: (BOOL *)abort;
- (void)BeginDownloadFile: (NSString *)path 
    skip:(BOOL *)skip;

@end


MyFtpProgress.mm:

@implementation MyFtpProgress

-(id)init {
    self = [super init];
    return self;
}

-(void)dealloc {
    [super dealloc];
}

-(void)dispose {
}

- (void)AbortCheck: (BOOL *)abort
{
    *abort = NO;
    FILE *fp = fopen("eventLog.txt","a");
    fprintf(fp,"AbortCheck\n");
    fclose(fp);

}
- (void)PercentDone: (NSNumber *)pctDone
              abort: (BOOL *)abort
{
    *abort = NO;
    FILE *fp = fopen("eventLog.txt","a");
    fprintf(fp,"PercentDone: %d\n",[pctDone intValue]);
    fclose(fp);
}

- (void)BeginDownloadFile: (NSString *)path 
    skip:(BOOL *)skip
{
    *skip = NO;
    FILE *fp = fopen("eventLog.txt","a");
    fprintf(fp,"BeginDownloadFile: %s\n",[path UTF8String]);
    fclose(fp);

}

@end


The code to create an instance of MyFtpProgress and assign it as the callback object looks like this:

        ftp = [[CkoFtp2 alloc] init]; 
progressObj = [[MyFtpProgress alloc] init];

        [ftp setEventCallbackObject:progressObj];


Answer

Thanks, I'll try it tomorrow!


Answer

Hello,

I have the same result, I'm able to show the percentage with NSLog but the progress bar isn't working.


Answer

Ray,

The callbacks are made in real time -- that is for sure. What is likely happening is that your user interface is not refreshing with the updates until the very end. The issue here is not with Chilkat, but with your application code involving user interface refreshing/updating.