Using Microsoft Sync Framework to sync files across network
Asked Answered
L

1

9

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.

Literality answered 28/1, 2011 at 4:26 Comment(1)
I tried, but it does not seem possible. The file provider uses a lot of internal classes and I see no way to proxy them.Nolita
I
2

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();
Inanity answered 9/11, 2011 at 22:53 Comment(2)
if I am using the network path using IP e.g. "\\10.1.1.102\\sharedPath", then it is not able to create the instance. Its just giving me the error that "could not find part of the file path". the same path I am able to access usng run command. what can be the problem???Jansenism
Maybe it's the \\ before sharedPath? I'm not sure.Inanity

© 2022 - 2024 — McMap. All rights reserved.