Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Microsoft Sync Framework to sync files across network

The file synchronization example given here - http://code.msdn.microsoft.com/Release/ProjectReleases.aspx?ProjectName=sync&ReleaseId=3424 only talks about syncing files on the same machine. Has anyone come across a working example of using something like WCF to enable this to work for files across a network?

Bryant's example - http://bryantlikes.com/archive/2008/01/03/remote-file-sync-using-wcf-and-msf.aspx is not complete and is only a one way sync and is less than ideal.

like image 405
Cranialsurge Avatar asked Jan 28 '11 04:01

Cranialsurge


People also ask

What is Microsoft Sync Framework Do I need it?

Microsoft Sync Framework is a comprehensive synchronization platform that enables collaboration and offline scenarios for applications, services, and devices. Using Microsoft Sync Framework, developers can build applications that synchronize data from any source using any protocol over any network.


1 Answers

The Sync framework can synchronize files across the network as long as you have an available network share.

In the constructor of the FileSyncProvider set the rootDirectoryPath to a network share location that you have read and write permissions to:

    string networkPath = @"\\machinename\sharedfolderlocation";

    FileSyncProvidor provider = new FileSyncProvider(networkPath);

To do a two way sync in this fashion you will need to create a FileSyncProvider for both the source and destination systems and use the SyncOrchestrator to do the heavy lifting for you.

An example:

    string firstLocation = @"\\sourcemachine\sourceshare";
    string secondLocation = @"\\sourcemachine2\sourceshare2";

    FileSyncProvidor firstProvider = new FileSyncProvider(firstLocation);
    FileSyncProvidor secondProvider = new FileSyncProvider(secondLocation);

    SyncOrchestrator orchestrator = new SyncOrchestrator();
    orchestrator.LocalProvider = firstProvider;
    orchestrator.RemoteProvider = secondProvider;
    orchestrator.Direction = SyncDirectionOrder.DownloadAndUpload;

What this does is define two filesync providers and the orchestrator will sync the files in both directions. It tracks creates, modifications, and deletes of files in the directories set in the providers.

All that is needed at this point is to call Synchronize on the SyncOrchestrator:

    orchestrator.Synchronize();
like image 170
Phil Patterson Avatar answered Oct 11 '22 21:10

Phil Patterson