(Unicode C) Get Filenames in a Remote Directory
Gets the names of files in a remote FTP directory.
#include <C_CkFtp2W.h>
void ChilkatSample(void)
{
HCkFtp2W ftp;
BOOL success;
int n;
int i;
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
ftp = CkFtp2W_Create();
CkFtp2W_putHostname(ftp,L"ftp.example.com");
CkFtp2W_putUsername(ftp,L"myLogin");
CkFtp2W_putPassword(ftp,L"myPassword");
// Use explicit TLS
CkFtp2W_putAuthTls(ftp,TRUE);
CkFtp2W_putPort(ftp,21);
// Connect and login to the FTP server.
success = CkFtp2W_Connect(ftp);
if (success != TRUE) {
wprintf(L"%s\n",CkFtp2W_lastErrorText(ftp));
CkFtp2W_Dispose(ftp);
return;
}
// Iterate over .txt files.
CkFtp2W_putListPattern(ftp,L"*.txt");
n = CkFtp2W_GetDirCount(ftp);
wprintf(L"n = %d\n",n);
i = 0;
while (i < n) {
wprintf(L"%d: %s\n",i,CkFtp2W_getFilename(ftp,i));
i = i + 1;
}
CkFtp2W_Dispose(ftp);
}
|