Xbase++
Xbase++
Get FTP Directory Listing Information
See more FTP Examples
_LANGUAGE_ example showing how to get information about files and subdirectories in the current remote FTP directory.Chilkat Xbase++ Downloads
LOCAL nSuccess
LOCAL oFtp
LOCAL i
LOCAL n
nSuccess := 0
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
oFtp := CreateObject("Chilkat.Ftp2")
oFtp:Hostname := "ftp.example.com"
oFtp:Username := "login"
oFtp:Password := "password"
// Connect and login to the FTP server.
nSuccess := oFtp:Connect()
IF (nSuccess != 1)
? oFtp:LastErrorText
oFtp:destroy()
RETURN
ENDIF
// The ListPattern property is our directory listing filter.
// The default value is "*", which includes everything.
? oFtp:ListPattern
// To get file and sub-directory information, simply
// loop from 0 to ftp.GetDirCount() - 1
n := oFtp:GetDirCount()
IF (n < 0)
? oFtp:LastErrorText
oFtp:destroy()
RETURN
ENDIF
IF (n > 0)
FOR i := 0 TO n - 1
// Display the filename
? oFtp:GetFilename(i)
// Display the file size (in bytes)
? Str(oFtp:GetSize(i))
// Is this a sub-directory?
IF (oFtp:GetIsDirectory(i) == 1)
? ".. this is a sub-directory"
ENDIF
? "--"
NEXT
ENDIF
? "-----------------------------------"
// Only files and directories
// matching the ListPattern are returned.
oFtp:ListPattern := "*.asp"
n := oFtp:GetDirCount()
IF (n < 0)
? oFtp:LastErrorText
oFtp:destroy()
RETURN
ENDIF
IF (n > 0)
FOR i := 0 TO n - 1
// Display the filename
? oFtp:GetFilename(i)
// Display the file size (in bytes)
? Str(oFtp:GetSize(i))
? "--"
NEXT
ENDIF
nSuccess := oFtp:Disconnect()
oFtp:destroy()