0
votes

I need to do basic one way file synchronization from local to remote server. I tried to use Microsoft Sync Framework, and it works just fine. However, I will need two features which I can not get now:

  1. If file has been deleted on the destination, next synchronization should recreate it from the source
  2. If file has been changed on the destination, next synchronization should replace it from the source

Is it possible to get that by using some options in SyncOrchestrator.Synchronize() function ?

Existing code is based on MSDN article:

public static void SyncFileSystemReplicaOneWay(string sourcePath, string destinationPath)
{
        FileSyncProvider sourceProvider = null;
        FileSyncProvider destinationProvider = null;

        try
        {
                sourceProvider = new FileSyncProvider(sourcePath);
                destinationProvider = new FileSyncProvider(destinationPath);

                var agent = new SyncOrchestrator();
                agent.LocalProvider = sourceProvider;
                agent.RemoteProvider = destinationProvider;
                agent.Direction = SyncDirectionOrder.Upload;

                var stats = agent.Synchronize();
        }

        finally
        {
                if (sourceProvider != null) sourceProvider.Dispose();
                if (destinationProvider != null) destinationProvider.Dispose();
        }
}
1

1 Answers

1
votes

both scenarios will not work out of the box without additional code.

when a sync is done, it detects changes in the source and applies it on destination.

if your case, the change was made on the destination and the source has no way of telling that you deleted a file on destination to include it on change enumeration. if the file on source is modified, you will have better luck as that would be result to a conflict and offer you the opportunity to override the delete on the destination with the file from the source.

same for your second question.

an alternative will be to run detect changes on destination, find out which file were deleted/updated and grabbing those files from the source.