Synchronizing Folders with the TE (Synchronize)

Use the Synchronize method to perform one or two way mirrors of a remote and local folder's contents.

The synchronize method contains as many as 9 parameters. Be sure to use absolute path names for both local and remote folder paths.

Syntax

Object.Synchronize(BSTR bstrRemoteName, BSTR bstrLocalName, long nDirection, long nAction, long nCasehandling, BOOL bRecursive, BOOL bIgnoreLinks, BOOL bDelDestination, BOOL bPromptDel);

Parameters

#

Name

Value

1

BstrRemoteName

String value that specifies the absolute path name of the remote folder

2

BstrLocalName

String value that specifies the absolute path name of the local folder

3

nDirection

0 = Mirror Local (make the remote look just like the local)

1 = Mirror Remote (make the local look just like the remote)

2 = Mirror Both

4

nAction

When nDirection = 2 (Mirror Both)

0 = Mirror the more recent file

1 = Mirror the larger file

2 = Prompt for matching file names

3 = Skip mirroring files with the same names

-----------------------------------------------------------------

When nDirection = 0 or 1 (Mirror Local or Remote)

0 = Use Global Overwrite settings in the CuteFTP shell for matching filenames

1 = Always overwrite the file with a matching name

2 = Numerate the file (filename[1])

3 = Skip

5

nCaseHandling

0 = Transfer first and skip the rest (default)

1 = Show rename prompt

2 = Numerate

Note: This action applies when matching filenames are found and the only difference is the filename case.

6

bRecursive

0 = Don't sync subfolders

1 = Apply sync to subfolders (default)     

7

bIgnoreLinks

0 = Don't ignore symbolic links

1 = Ignore symbolic links (default)

8

bDelDestination

0 = Don't remove destination

1 = Remove destination if source does not exist (default)

Note: This action only applies to one-way mirroring. If a file exists in the destination that isn't in the source being mirrored, then delete the destination file.

9

bPromptDel

0 = Don't prompt before removing destination

1 = Prompt before removing destination (default)

Note: Only applies to one-way mirroring when DelDestination is True.

 

Examples

'Simple synchronize using minimal parameters

Set MySite = CreateObject("CuteFTPPro.TEConnection")

'Don't forget to initialize all necessary fields for MySite : host name, user, password, etc.

 

MySite.Connect

MySite.Synchronize "/pub/myfolder", "C:\mysitesfiles", 0, 1

'This will perform a local mirror, overwriting any matching filename.

 

'Simple synchronize using minimal parameters

Set MySite = CreateObject("CuteFTPPro.TEConnection")

'Don't forget to initialize all necessary fields for MySite : host name, user, password, etc.

 

MySite.Connect

MySite.Synchronize "/pub/myfolder", "C:\mysitesfiles", 2, 0

'This will perform full mirror (both), overwriting older files when a matching filename is found.

 

'Slightly more complex synchronize routine used to synchronize bookmarks. Uses variables for the path names

strRemotePath = "\Favorites"

strLocalPath = "C:\Documents and Settings\username\Favorites"

'Don't forget to initialize all necessary fields for MySite : host name, user, password, etc.

MySite.Connect

            If (Not (MySite.IsConnected)) Then

            MsgBox "Unable to connect to server:" + MySite.Host

            End if

MySite.Synchronize strRemotePath, strLocalPath, 2, 3, 0, 1, 1, 0, 1

'Performs a full mirror, skips matching filenames, transfers only the first file if multiple files are found with the same name but different case, applies to subfolders, ignores symbolic links, does not remove destination files if the source doesn't exist (N/A when dealing with dual mirror), and prompt prior to deleting anything (N/A when dealing with dual mirror).

MsgBox "DONE!" 'Alert me to the completed task

MySite.Disconnect'Disconnects from the site when done

MySite.Close'Close the Transfer Engine process

'A full synchronizaiton VB subroutine:

Sub Sync()

           >Dim MySite

            Set MySite = CreateObject("CuteFTPPro.TEConnection")

            strHost = "ftp.yourhost.com"

            strPath = "/pub"

            strLocalPath = "c:\temp\sync_test"

 

            strHost = InputBox("Enter host", "CuteFTP Pro", strHost)

            strPath = InputBox("Enter remote path", "CuteFTP Pro", strPath)

            strLocalPath = InputBox("Enter local path", "CuteFTP Pro", strLocalPath)

 

            MySite.Host = strHost

 

            MySite.CaseHandling = 1

            MySite.Recursive = False

            MySite.IgnoreLinks = True

            MySite.DeleteDestination = False

            MySite.PromptDelete = True

 

nUserChoise = MsgBox ("Mirror remote: " & strHost & strPath & " to local " & strLocalPath & " ?", vbYesNoCancel)

            If nUserChoise = vbYes Then

                        MySite.Synchronize strPath, strLocalPath, 1, 0

            else

nUserChoise = MsgBox ("Mirror local: " & strHost & strLocalPath & " to remote " & strPath & " ?", vbYesNoCancel)

                        If nUserChoise = vbYes Then

                                    MySite.Synchronize strPath, strLocalPath, 0, 0

                        else

nUserChoise = MsgBox ("Mirror both: " & strHost & strPath & " <- > " & strLocalPath & " ?", vbYesNoCancel)

                                    If nUserChoise = vbYes Then

                                                MySite.Synchronize strPath, strLocalPath, 2, 1

                                    else

                                    End if

                        End if

            End if

End Sub