(Objective-C) Get Filenames in a Remote Directory
Gets the names of files in a remote FTP directory.
#import <CkoFtp2.h>
// 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.
BOOL 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;
}
|