Xbase++
Xbase++
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 Xbase++ Downloads
LOCAL nSuccess
LOCAL oSftp
LOCAL cRemoteDir
LOCAL cLocalDir
LOCAL nMode
LOCAL nRecursive
nSuccess := 0
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
oSftp := CreateObject("Chilkat.SFtp")
nSuccess := oSftp:Connect("my-ssh-server.com", 22)
IF (nSuccess == 1)
nSuccess := oSftp:AuthenticatePw("mySshLogin", "mySshPassword")
ENDIF
IF (nSuccess == 1)
nSuccess := oSftp:InitializeSftp()
ENDIF
IF (nSuccess != 1)
? oSftp:LastErrorText
oSftp:destroy()
RETURN
ENDIF
// 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
oSftp:SyncMustMatch := "*.eml; *.gif"
cRemoteDir := "syncDownloadTest/someDir"
cLocalDir := "qa_output"
// mode=0: Download all matching files according to SyncMustMatch
nMode := 0
// do not recursively traverse the remote directory tree.
nRecursive := 0
nSuccess := oSftp:SyncTreeDownload(cRemoteDir, cLocalDir, nMode, nRecursive)
IF (nSuccess != 1)
? oSftp:LastErrorText
oSftp:destroy()
RETURN
ENDIF
? "Success."
oSftp:destroy()