![]() |
Chilkat • HOME • Android™ • AutoIt • C • C# • C++ • Chilkat2-Python • CkPython • Classic ASP • DataFlex • Delphi DLL • Go • Java • Node.js • Objective-C • PHP Extension • Perl • PowerBuilder • PowerShell • PureBasic • Ruby • SQL Server • Swift • Tcl • Unicode C • Unicode C++ • VB.NET • VBScript • Visual Basic 6.0 • Visual FoxPro • Xojo Plugin
(Unicode C) FTP Iterate over Files in Directory Matching ListPatternSee more RSA ExamplesUses the ListPattern property to iterate over the files in a directory matching the pattern.
#include <C_CkFtp2W.h> #include <C_CkStringBuilderW.h> void ChilkatSample(void) { HCkFtp2W ftp; BOOL success; int n; int i; const wchar_t *filename; HCkStringBuilderW sbLocalPath; // 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"my_login"); CkFtp2W_putPassword(ftp,L"my_password"); CkFtp2W_putPort(ftp,21); CkFtp2W_putAuthTls(ftp,TRUE); success = CkFtp2W_Connect(ftp); if (success != TRUE) { wprintf(L"%s\n",CkFtp2W_lastErrorText(ftp)); CkFtp2W_Dispose(ftp); return; } // Change to the "images" sub-directory located under our FTP account's home directory. success = CkFtp2W_ChangeRemoteDir(ftp,L"images"); if (success != TRUE) { wprintf(L"%s\n",CkFtp2W_lastErrorText(ftp)); CkFtp2W_Dispose(ftp); return; } CkFtp2W_putListPattern(ftp,L"*.png"); // Fetch the current remote directory contents by calling GetDirCount n = CkFtp2W_GetDirCount(ftp); if (n < 0) { wprintf(L"%s\n",CkFtp2W_lastErrorText(ftp)); CkFtp2W_Dispose(ftp); return; } i = 0; sbLocalPath = CkStringBuilderW_Create(); while (i < n) { filename = CkFtp2W_getFilename(ftp,i); wprintf(L"%s\n",filename); // Download this file. CkStringBuilderW_SetString(sbLocalPath,L"qa_output/"); CkStringBuilderW_Append(sbLocalPath,filename); success = CkFtp2W_GetFile(ftp,filename,CkStringBuilderW_getAsString(sbLocalPath)); if (success != TRUE) { wprintf(L"%s\n",CkFtp2W_lastErrorText(ftp)); CkFtp2W_Dispose(ftp); CkStringBuilderW_Dispose(sbLocalPath); return; } i = i + 1; } CkFtp2W_Dispose(ftp); CkStringBuilderW_Dispose(sbLocalPath); } |
© 2000-2025 Chilkat Software, Inc. All Rights Reserved.