• Loading...
ComponentPro UltimateSftp

Mirror directories

Language Filter: AllSend comments on this topic to ComponentPro

In addition to supporting standard file transfer methods, the Ultimate SFTP component also offers a set of easy-to-use methods to mirror folders. To mirror a local folder with a remote folder, call the QuickSynchronize method of the Sftp.

The following steps show you how to use the QuickSynchronize method to synchronize a remote folder with a local folder.

using ComponentPro.IO;
using ComponentPro.Net;


Sftp client = new Sftp();

// Connect to the SFTP server.
client.Connect("myserver", 21);

// Authenticate.
client.Authenticate("userName", "password");

// Create a new instance of the QuickSyncOptions class.
QuickSyncOptions opt = new QuickSyncOptions();

// Set synchronization's settings
opt.Comparer = FileComparers.FileContentComparer;
opt.Recursive = true;

// Synchronize folders.
    "/", // Source directory. 
    "c:\\test", // Destination directory. This local dir will be identical to the remote dir ('/'). 
    true, // Remote dir is master 

// Do something here 
// ...

The QuickSynchronize method is a one-way synchronization, To truely synchronize files and folders in a two-way synchronization, use the Synchronizer class which is available in ComponentPro.FileSync assembly. See Synchronize files and Synchronize directories topics for more details.