Sample code for 30+ languages & platforms
Objective-C

Get Filenames in a Remote Directory

Gets the names of files in a remote FTP directory.

Chilkat Objective-C Downloads

Objective-C
#import <CkoFtp2.h>

BOOL success = NO;

//  This example requires the Chilkat API to have been previously unlocked.
//  See Global Unlock Sample for sample code.

CkoFtp2 *ftp = [[CkoFtp2 alloc] init];

ftp.Hostname = @"ftp.example.com";
ftp.Username = @"myLogin";
ftp.Password = @"myPassword";
//  Use explicit TLS
ftp.AuthTls = YES;
ftp.Port = [NSNumber numberWithInt:21];

//  Connect and login to the FTP server.
success = [ftp Connect];
if (success != YES) {
    NSLog(@"%@",ftp.LastErrorText);
    return;
}

//  Iterate over .txt files.
ftp.ListPattern = @"*.txt";
int n = [[ftp GetDirCount] intValue];
NSLog(@"%@%d",@"n = ",n);

int i = 0;
while (i < n) {

    NSLog(@"%d%@%@",i,@": ",[ftp GetFilename: [NSNumber numberWithInt: i]]);

    i = i + 1;
}