Differences

This shows you the differences between the selected revisions of the page.

scriptcommand_synchronize 2013-04-15 scriptcommand_synchronize 2024-04-25 (current)
Line 1: Line 1:
-====== synchronize ====== +====== synchronize command ====== 
-[[task_synchronize_full|Synchronizes directories]].+[[task_synchronize_full|Synchronizes]] content of a local directory with a remote one or vice versa or mutually. 
 + 
 +===== [[syntax]] Syntax =====
  synchronize local|remote|both [ <local directory> [ <remote directory> ] ]   synchronize local|remote|both [ <local directory> [ <remote directory> ] ]
-When the first parameter is ''local'', changes from remote directory are applied to local directory. When the first parameter is ''remote'', changes from the local directory are applied to the remote directory. When the first parameter is ''both'', both local and remote directories can be modified.+===== Remarks ===== 
 + 
 +When the first parameter is ''==local=='', changes from remote directory are applied to local directory. When the first parameter is ''==remote=='', changes from the local directory are applied to the remote directory. When the first parameter is ''==both=='', both local and remote directories can be modified.
When directories are not specified, current working directories are synchronized. When directories are not specified, current working directories are synchronized.
Line 12: Line 16:
Switches: Switches:
^ Switch                  ^ Description ^ ^ Switch                  ^ Description ^
-| ''-delete''              | Delete obsolete files. Ignored for ''both''. | +| ''-==preview==''            | Preview changes only, do not synchronize. Transfer settings switches ''[[#permissions|-permissions]]'', ''[[#nopermissions|-nopermissions]]'', ''[[#speed|-speed]]'', ''[[#transfer|-transfer]]'' and ''[[#resumesupport|-resumesupport]]'' have no effect. | 
-| ''-mirror''              | [[task_synchronize_full#synchronization_mode|Mirror mode]] (synchronize also older files). Ignored for ''both''.  | +| ''-==delete==''              | Delete obsolete files. Ignored for ''[[#both|both]]'' mode. | 
-| ''-criteria=<criteria>'' | [[ui_synchronize#comparison_criteria|Comparison criteria]]. Possible values are ''time'', ''size'', ''either'' and ''none''. Ignored for ''both'' mode. | +| ''-==mirror==''              | [[task_synchronize_full#mode|Mirror mode]] (synchronize also older files). Ignored for ''[[#both|both]]'' mode.  | 
-| ''-permissions=<mode>''  | Set permissions ([[SFTP]] and [[SCP]] protocols only) | +| ''-==criteria===<criteria>'' | [[ui_synchronize#criteria|Comparison criteria]]. A comma-separated list of any of ''time'', ''size'' and ''checksum'', or ''none''. For backward compatibility, ''either'' is an alias to ''time,size''. Ignored for ''[[#both|both]]'' mode. | 
-| ''-nopermissions''      | Keep default permissions | +| ''-==preservetime==''        | Preserve timestamp. Enforced by default unless ''[[#criteria|-criteria]]'' lacks ''time''. | 
-| ''-speed=<kibps>'' ······| Limit transfer speed | +| ''-==nopreservetime==''      | Do not preserve timestamp. Ignored unless ''[[#criteria|-criteria]]'' lacks ''time''. | 
-| ''-transfer=<mode>''    | ''%%binary|ascii|automatic%%'' \\ [[transfer_mode|Transfer mode]]: binary, ascii (text), automatic (by extension). |  +| ''-==permissions===<mode>''  | Set permissions ([[SFTP]] and [[SCP]] protocols only).
-| ''-filemask=<mask>''    | ''%%<mask>[;<mask2>...]%%'' \\ Sets [[file_mask|file mask]]. | +| ''-==nopermissions==''      | Keep default permissions.
-| ''-resumesupport=·<state>'' | ''%%on|off|<threshold>%%'' \\ Configures [[resume#automatic|automatic resume/transfer to temporary filename]]. | +| ''-==speed===<kbps>'' ·······| Limit transfer speed (in KB/s).
 +| ''-==transfer===<mode>''    | ''%%binary|ascii|automatic%%'' \\ [[transfer_mode|Transfer mode]]: binary, ascii (text), automatic (by extension). |  
 +| ''-==filemask===<mask>''    | ''%%<mask>[;<mask2>...]%%'' \\ Sets [[file_mask|file mask]]. | 
 +| ''-==resumesupport===<state>'' | ''%%on|off|<threshold>%%'' \\ Configures [[resume#automatic|automatic resume/transfer to temporary filename]]. |  
 +| ''-==rawtransfersettings== setting1=value1 setting2=value2 ...'' | Allows configuring any transfer settings using [[rawtransfersettings|raw format]] as in an INI file. E.g. to enable preserving of directory timestamps, use ''-rawtransfersettings PreserveTimeDirs=1''. The switch should come only after other parameters. |
-Effective [[scriptcommand_option|options]]: ''reconnecttime''+Effective [[scriptcommand_option|options]]: ''[[scriptcommand_option#reconnecttime|reconnecttime]]'', ''[[scriptcommand_option#failonnomatch|failonnomatch]]''
-XML log elements: ''[[logging_xml#download|download]]'' (with ''local'' or ''both''), ''[[logging_xml#upload|upload]]'' (with ''remote'' or ''both''), ''[[logging_xml#touch|touch]]'' (with ''remote'' or ''both''), ''[[logging_xml#chmod|chmod]]'' (with ''remote'' or ''both'' and ''-permissions''), ''[[logging_xml#rm|rm]]'' (with ''remote'' and ''-delete'')+XML log elements: ''[[logging_xml#download|download]]'' (with ''[[#local|local]]'' or ''[[#both|both]]''), ''[[logging_xml#upload|upload]]'' (with ''[[#remote|remote]]'' or ''both''), ''[[logging_xml#mkdir|mkdir]]'', ''[[logging_xml#touch|touch]]'' (with ''remote'' or ''both''), ''[[logging_xml#chmod|chmod]]'' (with ''remote'' or ''both'' and ''[[#permissions|-permissions]]''), ''[[logging_xml#rm|rm]]'' (with ''remote'' and ''[[#delete|-delete]]'')
-===== Examples =====+===== [[examples]] Examples ===== 
 +<code winscp> 
 +synchronize both 
 +</code> 
 +<code winscp> 
 +synchronize remote -delete d:\www /home/martin/public_html 
 +</code>
<code winscp> <code winscp>
-synchronize remote -delete 
-synchronize both d:\www /home/martin/public_html 
synchronize both -filemask="|*.bak; *.tmp" synchronize both -filemask="|*.bak; *.tmp"
</code> </code>
 +===== [[net]] Converting to .NET Assembly =====
 +When [[library_from_script|converting script to .NET Assembly]], map ''synchronize'' command to ''[[library_session_synchronizedirectories|Session.SynchronizeDirectories]]'' method.
 +
 +Parameters mapping: Command parameter ''local|remote|both'' maps to method parameter ''mode'', with values ''SynchronizationMode.Local'', ''SynchronizationMode.Remote'' and ''SynchronizationMode.Both'', respectively ([[library_powershell#enums|Enumeration syntax]] in PowerShell is like ''[WinSCP.SynchronizationMode]::Local''). Command parameter ''local directory'' maps to method parameter ''localPath''. Command parameter ''remote directory'' maps to method parameter ''remotePath''. You have to [[library_from_script#paths|convert relative paths to absolute paths]].
 +
 +Switches mapping:
 +^ Switch                  ^ Mapping ^
 +| ''-preview''            | Use [[library_session_comparedirectories|''Session.CompareDirectories'' method]] instead of ''Session.SynchronizeDirectories''. |
 +| ''-delete''              | Value ''true'' (''$True'' in PowerShell) for method parameter ''removeFiles''. |
 +| ''-mirror''              | Value ''true'' (''$True'') for method parameter ''mirror''. |
 +| ''-criteria''            | Set method parameter ''criteria''. Use ''SynchronizationCriteria.Time'' for ''time'', ''SynchronizationCriteria.Size'' for ''size'', ''SynchronizationCriteria.Checksum'' for ''checksum'' and ''SynchronizationCriteria.None'' for ''none''. \\ [[library_powershell#enums|Enumeration syntax]] in PowerShell is like ''[WinSCP.SynchronizationCriteria]::Time''. |
 +| ''-permissions'' \\ ''-nopermissions'' \\  ''-transfer'' \\ ''-filemask'' \\ ''-resumesupport'' \\ ''-speed=<kbps>'' | [[library_from_script_transfer_settings|Converting transfer settings scripting switches]] to .NET assembly class ''TransferSettings''. |
 +
 +To emulate the ([[scripting#using_scripting|default]]) ''[[scriptcommand_option#batch|option batch abort]]'' mode, call ''[[library_operationresultbase|TransferOperationResult.Check]]'' on method's result. See also [[library_session#results|Capturing results of operations]].
 +
 +For example, following script snippet:
 +
 +<code winscp>
 +synchronize both d:\www /home/martin/public_html
 +</code>
 +
 +maps to following [[library_powershell|PowerShell]] code:
 +
 +<code powershell>
 +$synchronizationResult =
 +    $session.SynchronizeDirectories(
 +        [WinSCP.SynchronizationMode]::Both, "d:\www", "/home/martin/public_html", $False)
 +# Throw on any error to emulate the (default) "option batch abort" mode
 +$synchronizationResult.Check()
 +</code>

Last modified: by martin