Differences

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

library_session_synchronizedirectories 2017-12-05 library_session_synchronizedirectories 2024-02-15 (current)
Line 1: Line 1:
====== Session.SynchronizeDirectories Method ====== ====== Session.SynchronizeDirectories Method ======
-[[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 =====
Line 17: Line 17:
<code vbnet *> <code vbnet *>
Public Function SynchronizeDirectories( Public Function SynchronizeDirectories(
-    ByVal mode As SynchronizationMode, +    mode As SynchronizationMode, 
-    ByVal localPath As String, +    localPath As String, 
-    ByVal remotePath As String, +    remotePath As String, 
-    ByVal removeFiles As Boolean, +    removeFiles As Boolean, 
-    ByVal Optional mirror As Boolean = False, +    Optional mirror As Boolean = False, 
-    ByVal Optional criteria As SynchronizationCriteria = 1+    Optional criteria As SynchronizationCriteria = SynchronizationCriteria.Time
-    ByVal Optional options As TransferOptions = Nothing+    Optional options As TransferOptions = Nothing
) As SynchronizationResult ) As SynchronizationResult
</code> </code>
-==== Parameters ====+==== [[parameters]] Parameters ====
^ Name ^ Description ^ ^ Name ^ Description ^
-| SynchronizationMode ==mode== | [[task_synchronize_full#mode|Synchronization mode]]. Possible values are ''SynchronizationMode.Local'', ''SynchronizationMode.Remote'' and ''SynchronizationMode.Both''.  |+| SynchronizationMode ==mode== | [[task_synchronize_full##direction|Synchronization direction]]. Possible values are ''SynchronizationMode.Local'', ''SynchronizationMode.Remote'' and ''SynchronizationMode.Both''.  |
| string ==localPath== | Full path to local directory. | | string ==localPath== | Full path to local directory. |
| string ==remotePath== | Full path to remote directory. | | string ==remotePath== | Full path to remote directory. |
| bool ==removeFiles== | When set to ''true'', deletes obsolete files. Cannot be used for ''SynchronizationMode.Both''. | | bool ==removeFiles== | When set to ''true'', deletes obsolete files. Cannot be used for ''SynchronizationMode.Both''. |
| bool ==mirror== | When set to ''true'', synchronizes in [[task_synchronize_full#mode|mirror mode]] (synchronizes also older files). Cannot be used for ''SynchronizationMode.Both''. Defaults to ''false''. | | bool ==mirror== | When set to ''true'', synchronizes in [[task_synchronize_full#mode|mirror mode]] (synchronizes also older files). Cannot be used for ''SynchronizationMode.Both''. Defaults to ''false''. |
-| SynchronizationCriteria ==criteria== | [[ui_synchronize#criteria|Comparison criteria]]. Possible values are ''SynchronizationCriteria.None'', ''SynchronizationCriteria.Time'' (default), ''SynchronizationCriteria.Size'' and ''SynchronizationCriteria.Either''. For ''SynchronizationMode.Both'' ''SynchronizationCriteria.Time'' can be used only. |+| SynchronizationCriteria ==criteria== | [[ui_synchronize#criteria|Comparison criteria]]. The parameter is a bit field of any of ''SynchronizationCriteria.Time'' (default), ''SynchronizationCriteria.Size'' and ''SynchronizationCriteria.Checksum''. ''SynchronizationCriteria.None'' can be used as an alias to empty bit field. For backward compatibility, ''SynchronizationCriteria.Either'' can be used as an alias to ''Time %%|%% Size''. For ''SynchronizationMode.Both'', ''SynchronizationCriteria.Time'' can be used only. |
| [[library_transferoptions|TransferOptions]] ==options== | Transfer options. Defaults to ''null'', what is equivalent to ''new TransferOptions()''. | | [[library_transferoptions|TransferOptions]] ==options== | Transfer options. Defaults to ''null'', what is equivalent to ''new TransferOptions()''. |
Line 47: Line 47:
| TimeoutException | Timeout waiting for ''winscp.com'' to respond. | | TimeoutException | Timeout waiting for ''winscp.com'' to respond. |
-===== Remarks =====+===== [[remarks]] Remarks =====
Event ''[[library_session_filetransferred|Session.FileTransferred]]'' is raised for every uploaded or downloaded file. Event ''[[library_session_filetransferred|Session.FileTransferred]]'' is raised for every uploaded or downloaded file.
 +
 +To further customize the synchronization, use instead a combination of [[library_session_comparedirectories|''Session.CompareDirectories'']] and [[library_comparisondifference_resolve|''ComparisonDifference.Resolve'']]. This allows synchronizing only selected differences, changing synchronization order or customizing error handling.
===== [[example]] Examples ===== ===== [[example]] Examples =====
 +
==== [[csharp]] C# Example ==== ==== [[csharp]] C# Example ====
<code csharp> <code csharp>
Line 69: Line 72:
                UserName = "user",                 UserName = "user",
                Password = "mypassword",                 Password = "mypassword",
-                SshHostKeyFingerprint = "ssh-rsa 2048 xx:xx:xx:xx:xx:xx:xx:xx..."+                SshHostKeyFingerprint = "ssh-rsa 2048 xxxxxxxxxxx..."
            };             };
Line 168: Line 171:
                .UserName = "user"                 .UserName = "user"
                .Password = "mypassword"                 .Password = "mypassword"
-                .SshHostKeyFingerprint = "ssh-rsa 2048 xx:xx:xx:xx:xx:xx:xx:xx..."+                .SshHostKeyFingerprint = "ssh-rsa 2048 xxxxxxxxxxx..."
            End With             End With
Line 180: Line 183:
                ' Synchronize files                 ' Synchronize files
                Dim synchronizationResult As SynchronizationResult                 Dim synchronizationResult As SynchronizationResult
-                synchronizationResult = _ +                synchronizationResult = 
-                    session.SynchronizeDirectories( _+                    session.SynchronizeDirectories(
                        SynchronizationMode.Remote, "d:\www", "/home/martin/public_html", False)                         SynchronizationMode.Remote, "d:\www", "/home/martin/public_html", False)
Line 196: Line 199:
    End Function     End Function
-    Private Shared Sub FileTransferred(ByVal sender As Object, ByVal e As TransferEventArgs)+    Private Shared Sub FileTransferred(sender As Object, e As TransferEventArgs)
        If e.Error Is Nothing Then         If e.Error Is Nothing Then
Line 302: Line 305:
        UserName = "user"         UserName = "user"
        Password = "mypassword"         Password = "mypassword"
-        SshHostKeyFingerprint = "ssh-rsa 2048 xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx"+        SshHostKeyFingerprint = "ssh-rsa 2048 xxxxxxxxxxx..."
    }     }
Line 406: Line 409:
    sessionOptions.UserName = "user";     sessionOptions.UserName = "user";
    sessionOptions.Password = "mypassword";     sessionOptions.Password = "mypassword";
-    sessionOptions.SshHostKeyFingerprint = "ssh-rsa 2048 xx:xx:xx:xx:xx:xx:xx:xx...";+    sessionOptions.SshHostKeyFingerprint = "ssh-rsa 2048 xxxxxxxxxxx...";
    var session = WScript.CreateObject("WinSCP.Session", "session_");     var session = WScript.CreateObject("WinSCP.Session", "session_");
Line 438: Line 441:
</code> </code>
-==== Real-Life Example ====+==== [[reallife]] Real-Life Example ====
-  * [[library_example_delete_after_successful_download|Deleting remote files after successful remote to local synchronization]]; +  * [[library_example_delete_after_successful_download|*]].
-··* [[library_example_keep_local_directory_up_to_date|Keep local directory up to date (download changed files from remote SFTP/FTP server)]].+

Last modified: by martin