Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

File Synchronization

I'm writing an enterprise application that will sync local folders/files (One Way Server-->Local) with identical folders/files on a windows server network file share. I'm using the File.Copy method included with the .Net Framework and it works almost flawlessly. I copy files from the server if they do not exist on the local PC, if they do exist I compare modified dates and overwrite them if the server version is newer.

I run into problems when the application is copying a large file and gets interrupted for whatever the reason may be and the file being copied does not finish. The local file that was interrupted shows to be exactly the same size as the server copy even though only a fraction of it transferred but if you attempt to open it in this case lets say its a .zip or .pst file you can see that it is corrupted and will not open.

I either need a way to determine if a file was not fully transferred to delete it and transfer a fresh copy or perhaps a different method all together to accomplish what I'm attempting to do. Please keep in mind that speed is an issue.

like image 763
Skej Avatar asked Apr 27 '26 20:04

Skej


1 Answers

As a comprehensive solution, you might want to use Microsoft Sync framework to keep files in sync across devices.

For making sure that files are the same, you can calculate a hashsum for both files and compare them. For example using SHA algorithm. This will require reading both files completely, so it may affect your synchronization speed.

like image 100
alex Avatar answered Apr 29 '26 09:04

alex



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!