PowerBuilder
PowerBuilder
SFTP Download Files Matching a Pattern
See more SFTP Examples
Demonstrates how to download files in a directory matching one or more patterns (such as "*.zip" or "abc*_*0719.csv".Chilkat PowerBuilder Downloads
integer li_rc
integer li_Success
oleobject loo_Sftp
string ls_RemoteDir
string ls_LocalDir
integer li_Mode
integer li_Recursive
li_Success = 0
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
loo_Sftp = create oleobject
li_rc = loo_Sftp.ConnectToNewObject("Chilkat.SFtp")
if li_rc < 0 then
destroy loo_Sftp
MessageBox("Error","Connecting to COM object failed")
return
end if
li_Success = loo_Sftp.Connect("my-ssh-server.com",22)
if li_Success = 1 then
li_Success = loo_Sftp.AuthenticatePw("mySshLogin","mySshPassword")
end if
if li_Success = 1 then
li_Success = loo_Sftp.InitializeSftp()
end if
if li_Success <> 1 then
Write-Debug loo_Sftp.LastErrorText
destroy loo_Sftp
return
end if
// The SyncTreeDownload method can be used non-recursively to download all files matching a set of patterns.
// This example will download all files, but only those files having filenames
// that match *.csv and *.eml
loo_Sftp.SyncMustMatch = "*.eml; *.gif"
ls_RemoteDir = "syncDownloadTest/someDir"
ls_LocalDir = "qa_output"
// mode=0: Download all matching files according to SyncMustMatch
li_Mode = 0
// do not recursively traverse the remote directory tree.
li_Recursive = 0
li_Success = loo_Sftp.SyncTreeDownload(ls_RemoteDir,ls_LocalDir,li_Mode,li_Recursive)
if li_Success <> 1 then
Write-Debug loo_Sftp.LastErrorText
destroy loo_Sftp
return
end if
Write-Debug "Success."
destroy loo_Sftp