Chilkat HOME .NET Core C# Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi ActiveX Delphi DLL Go Java Lianja Mono C# Node.js Objective-C PHP ActiveX PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(DataFlex) 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.
Use ChilkatAx-win32.pkg Procedure Test Handle hoFtp Boolean iSuccess Boolean iDirExists Integer i Integer n Boolean iIsDir String sFname String sTemp1 // This example requires the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. Get Create (RefClass(cComChilkatFtp2)) To hoFtp If (Not(IsComObjectCreated(hoFtp))) Begin Send CreateComObject of hoFtp End Set ComHostname Of hoFtp To "ftp.example.com" Set ComUsername Of hoFtp To "login" Set ComPassword Of hoFtp To "password" // Connect and login to the FTP server. Get ComConnect Of hoFtp To iSuccess If (iSuccess <> True) Begin Get ComLastErrorText Of hoFtp To sTemp1 Showln sTemp1 Procedure_Return End // Does the "temp" directory exist? Get ComChangeRemoteDir Of hoFtp "/temp" To iDirExists If (iDirExists = True) Begin Showln "Yes, the temp directory exists." // Yes, it exists. Restore the current remote dir: Get ComChangeRemoteDir Of hoFtp ".." To iSuccess If (iSuccess <> True) Begin Get ComLastErrorText Of hoFtp To sTemp1 Showln sTemp1 Procedure_Return End End // Alternatively, you may set the ListPattern = "*" and // look for the directory: Set ComListPattern Of hoFtp To "*" Get ComGetDirCount Of hoFtp To n If (n < 0) Begin // Failed to get directory listing based on ListPattern Get ComLastErrorText Of hoFtp To sTemp1 Showln sTemp1 Procedure_Return End If (n > 0) Begin For i From 0 To (n - 1) Get ComGetIsDirectory Of hoFtp i To iIsDir If (iIsDir = True) Begin Get ComGetFilename Of hoFtp i To sFname If (sFname = "temp") Begin Showln "Found temp directory!" Get ComDisconnect Of hoFtp To iSuccess Procedure_Return End End Loop End Get ComDisconnect Of hoFtp To iSuccess End_Procedure |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.