Chilkat
HOME
Android™
ASP
Visual Basic
VB.NET
C#
iOS (IPhone)
Objective-C
C++
C
MFC
Delphi
FoxPro
Java
Perl
PHP Extension
PHP ActiveX
Python
PowerShell
Ruby
SQL Server
VBScript
Directory Existence CheckHow to test if a directory exists on an FTP server. A good way to check to see if a directory already exists is to try to "cd" to that remote directory by calling ChangeRemoteDir. If it succeeds, then the directory exists. If not, then it does not exist. An alternative method is to set the ListPattern = "*" and then iterate over the files/directories, looking for the directory. Downloads: MS Windows Visual C/C++ Libraries Linux/CentOS C/C++ Libraries MAC OS X C/C++ Libraries Solaris C/C++ Libraries C++ Builder Libraries FreeBSD C++ Libraries HP-UX C++ Libraries BlackBerry QNX C++ Libraries #include <C_CkFtp2.h> void ChilkatSample(void) { HCkFtp2 ftp; BOOL success; BOOL dirExists; long i; long n; BOOL foundDir; BOOL isDir; const char * fname; ftp = CkFtp2_Create(); // Any string unlocks the component for the 1st 30-days. success = CkFtp2_UnlockComponent(ftp,"Anything for 30-day trial"); if (success != TRUE) { printf("%s\n",CkFtp2_lastErrorText(ftp)); return; } CkFtp2_putHostname(ftp,"ftp.chilkatsoft.com"); CkFtp2_putUsername(ftp,"***"); CkFtp2_putPassword(ftp,"***"); // Connect and login to the FTP server. success = CkFtp2_Connect(ftp); if (success != TRUE) { printf("%s\n",CkFtp2_lastErrorText(ftp)); return; } // Does the "temp" directory exist? dirExists = CkFtp2_ChangeRemoteDir(ftp,"/temp"); if (dirExists == TRUE) { printf("Yes, the temp directory exists.\n"); // Yes, it exists. Restore the current remote dir: success = CkFtp2_ChangeRemoteDir(ftp,".."); if (success != TRUE) { printf("%s\n",CkFtp2_lastErrorText(ftp)); return; } } // Alternatively, you may set the ListPattern = "*" and // look for the directory: CkFtp2_putListPattern(ftp,"*"); n = CkFtp2_getNumFilesAndDirs(ftp); if (n < 0) { // Failed to get directory listing based on ListPattern printf("%s\n",CkFtp2_lastErrorText(ftp)); return; } foundDir = FALSE; if (n > 0) { for (i = 0; i <= n - 1; i++) { isDir = CkFtp2_GetIsDirectory(ftp,i); if (isDir == TRUE) { fname = CkFtp2_getFilename(ftp,i); if (fname == "temp") { printf("Found temp directory!\n"); foundDir = TRUE; break; } } } } if (foundDir != TRUE) { printf("temp directory not found!\n"); } CkFtp2_Disconnect(ftp); CkFtp2_Dispose(ftp); } |
Need a specific example? Send a request to support@chilkatsoft.com
© 2000-2010 Chilkat Software, Inc. All Rights Reserved.