Sample code for 30+ languages & platforms
Visual FoxPro

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 Visual FoxPro Downloads

Visual FoxPro
LOCAL lnSuccess
LOCAL loSftp
LOCAL lcRemoteDir
LOCAL lcLocalDir
LOCAL lnMode
LOCAL lnRecursive

lnSuccess = 0

* This example requires the Chilkat API to have been previously unlocked.
* See Global Unlock Sample for sample code.

loSftp = CreateObject('Chilkat.SFtp')

lnSuccess = loSftp.Connect("my-ssh-server.com",22)
IF (lnSuccess = 1) THEN
    lnSuccess = loSftp.AuthenticatePw("mySshLogin","mySshPassword")
ENDIF

IF (lnSuccess = 1) THEN
    lnSuccess = loSftp.InitializeSftp()
ENDIF

IF (lnSuccess <> 1) THEN
    ? loSftp.LastErrorText
    RELEASE loSftp
    CANCEL
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
loSftp.SyncMustMatch = "*.eml; *.gif"

lcRemoteDir = "syncDownloadTest/someDir"
lcLocalDir = "qa_output"

* mode=0: Download all matching files according to SyncMustMatch
lnMode = 0

* do not recursively traverse the remote directory tree.
lnRecursive = 0

lnSuccess = loSftp.SyncTreeDownload(lcRemoteDir,lcLocalDir,lnMode,lnRecursive)
IF (lnSuccess <> 1) THEN
    ? loSftp.LastErrorText
    RELEASE loSftp
    CANCEL
ENDIF

? "Success."

RELEASE loSftp