Sample code for 30+ languages & platforms
PowerBuilder

Filter Files and Directories in an FTP Sync

See more FTP Examples

Demonstrates the synchronization filter properties SyncMustMatch, SyncMustNotMatch, SyncMustMatchDir, SyncMustNotMatchDir, and SyncCreateAllLocalDirs.

Note: The local paths are relative to the application's current working directory. Absolute paths may also be used. Supply the paths appropriate to your own environment.

Background: A real sync rarely wants every file. These semicolon-separated wildcard filters shape the set: the MustMatch pairs include only matching files/directories, while the MustNotMatch pairs exclude them — letting you, say, publish only web assets while skipping build artifacts and caches. Directory filters also prune traversal, avoiding wasted time descending into folders you do not need. They apply to the tree-sync methods such as SyncLocalTree and SyncRemoteTree.

Chilkat PowerBuilder Downloads

PowerBuilder
integer li_rc
integer li_Success
oleobject loo_Ftp
integer li_Mode

li_Success = 0

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 = "myFtpLogin"

//  Normally you would not hard-code the password in source.  You should instead obtain it
//  from an interactive prompt, environment variable, or a secrets vault.
loo_Ftp.Password = "myPassword"

li_Success = loo_Ftp.Connect()
if li_Success = 0 then
    Write-Debug loo_Ftp.LastErrorText
    destroy loo_Ftp
    return
end if

li_Success = loo_Ftp.ChangeRemoteDir("public_html")
if li_Success = 0 then
    Write-Debug loo_Ftp.LastErrorText
    destroy loo_Ftp
    return
end if

//  Include only files matching these semicolon-separated, case-insensitive wildcard patterns.
loo_Ftp.SyncMustMatch = "*.html;*.css;*.js"

//  Exclude files matching these patterns, even if they matched SyncMustMatch.
loo_Ftp.SyncMustNotMatch = "*.tmp;*.bak"

//  Restrict which directories are traversed (and which are skipped) during a tree sync.
loo_Ftp.SyncMustMatchDir = "assets;pages"
loo_Ftp.SyncMustNotMatchDir = "cache;node_modules"

//  For a download sync, create empty remote directories on the local side too.
loo_Ftp.SyncCreateAllLocalDirs = 1

//  The filters apply to the tree sync operations, such as SyncLocalTree.
li_Mode = 6
li_Success = loo_Ftp.SyncLocalTree("qa_output/site",li_Mode)
if li_Success = 0 then
    Write-Debug loo_Ftp.LastErrorText
    destroy loo_Ftp
    return
end if

Write-Debug "Filtered sync complete."

li_Success = loo_Ftp.Disconnect()
if li_Success = 0 then
    Write-Debug loo_Ftp.LastErrorText
    destroy loo_Ftp
    return
end if



destroy loo_Ftp