SQL Server
SQL Server
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 SQL Server Downloads
--
CREATE PROCEDURE ChilkatSample
AS
BEGIN
DECLARE @hr int
DECLARE @sTmp0 nvarchar(4000)
DECLARE @success int
SELECT @success = 0
DECLARE @ftp int
EXEC @hr = sp_OACreate 'Chilkat.Ftp2', @ftp OUT
IF @hr <> 0
BEGIN
PRINT 'Failed to create ActiveX component'
RETURN
END
EXEC sp_OASetProperty @ftp, 'Hostname', 'ftp.example.com'
EXEC sp_OASetProperty @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.
EXEC sp_OASetProperty @ftp, 'Password', 'myPassword'
EXEC sp_OAMethod @ftp, 'Connect', @success OUT
IF @success = 0
BEGIN
EXEC sp_OAGetProperty @ftp, 'LastErrorText', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @ftp
RETURN
END
EXEC sp_OAMethod @ftp, 'ChangeRemoteDir', @success OUT, 'public_html'
IF @success = 0
BEGIN
EXEC sp_OAGetProperty @ftp, 'LastErrorText', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @ftp
RETURN
END
-- Include only files matching these semicolon-separated, case-insensitive wildcard patterns.
EXEC sp_OASetProperty @ftp, 'SyncMustMatch', '*.html;*.css;*.js'
-- Exclude files matching these patterns, even if they matched SyncMustMatch.
EXEC sp_OASetProperty @ftp, 'SyncMustNotMatch', '*.tmp;*.bak'
-- Restrict which directories are traversed (and which are skipped) during a tree sync.
EXEC sp_OASetProperty @ftp, 'SyncMustMatchDir', 'assets;pages'
EXEC sp_OASetProperty @ftp, 'SyncMustNotMatchDir', 'cache;node_modules'
-- For a download sync, create empty remote directories on the local side too.
EXEC sp_OASetProperty @ftp, 'SyncCreateAllLocalDirs', 1
-- The filters apply to the tree sync operations, such as SyncLocalTree.
DECLARE @mode int
SELECT @mode = 6
EXEC sp_OAMethod @ftp, 'SyncLocalTree', @success OUT, 'qa_output/site', @mode
IF @success = 0
BEGIN
EXEC sp_OAGetProperty @ftp, 'LastErrorText', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @ftp
RETURN
END
PRINT 'Filtered sync complete.'
EXEC sp_OAMethod @ftp, 'Disconnect', @success OUT
IF @success = 0
BEGIN
EXEC sp_OAGetProperty @ftp, 'LastErrorText', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @ftp
RETURN
END
EXEC @hr = sp_OADestroy @ftp
END
GO