Xbase++
Xbase++
Download Multiple Files Matching Pattern
See more FTP Examples
The MGetFiles method can be called to download all files matching a wildcarded filename pattern.Chilkat Xbase++ Downloads
LOCAL nSuccess
LOCAL oFtp
LOCAL nNumFilesDownloaded
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 := "myUsername"
oFtp:Password := "myPassword"
oFtp:Port := 21
oFtp:AuthTls := 1
// Connect and login to the FTP server.
nSuccess := oFtp:Connect()
IF (nSuccess != 1)
? oFtp:LastErrorText
oFtp:destroy()
RETURN
ENDIF
// Change to the remote directory where the files are located.
// This step is only necessary if the files are not in the root directory
// of the FTP account.
nSuccess := oFtp:ChangeRemoteDir("qa")
IF (nSuccess != 1)
? oFtp:LastErrorText
oFtp:destroy()
RETURN
ENDIF
// Download all files with filenames matching "*.txt";
// The files are downloaded into c:/temp/qa_output
nNumFilesDownloaded := oFtp:MGetFiles("*.txt", "c:/temp/qa_output")
IF (nNumFilesDownloaded < 0)
? oFtp:LastErrorText
oFtp:destroy()
RETURN
ENDIF
nSuccess := oFtp:Disconnect()
? Str(nNumFilesDownloaded) + " Files Downloaded!"
oFtp:destroy()