PowerBuilder
PowerBuilder
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 PowerBuilder Downloads
integer li_rc
integer li_Success
oleobject loo_Ftp
integer li_NumFilesDownloaded
li_Success = 0
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
loo_Ftp = create oleobject
li_rc = loo_Ftp.ConnectToNewObject("Chilkat.Ftp2")
if li_rc < 0 then
destroy loo_Ftp
MessageBox("Error","Connecting to COM object failed")
return
end if
loo_Ftp.Hostname = "ftp.example.com"
loo_Ftp.Username = "myUsername"
loo_Ftp.Password = "myPassword"
loo_Ftp.Port = 21
loo_Ftp.AuthTls = 1
// Connect and login to the FTP server.
li_Success = loo_Ftp.Connect()
if li_Success <> 1 then
Write-Debug loo_Ftp.LastErrorText
destroy loo_Ftp
return
end if
// 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.
li_Success = loo_Ftp.ChangeRemoteDir("qa")
if li_Success <> 1 then
Write-Debug loo_Ftp.LastErrorText
destroy loo_Ftp
return
end if
// Download all files with filenames matching "*.txt"
// The files are downloaded into c:/temp/qa_output
li_NumFilesDownloaded = loo_Ftp.MGetFiles("*.txt","c:/temp/qa_output")
if li_NumFilesDownloaded < 0 then
Write-Debug loo_Ftp.LastErrorText
destroy loo_Ftp
return
end if
li_Success = loo_Ftp.Disconnect()
Write-Debug string(li_NumFilesDownloaded) + " Files Downloaded!"
destroy loo_Ftp