tags:

views:

358

answers:

1

I would like to ask if anyone knows about reliability of File.Copy in a UNC path file copy. I have a file locally and the target is an smb share (SAMBA etc). Take for granted that the impersonation has took place successfully and I can execute commands with full credentials. Is there any way to check whether the file is properly copied?

-The solution of an integrity test will require to transfer data back, as the CIFS underlying protocol doesn't have the relevant control mechanisms (md5, etc).

-The only thing I have found is that the protocol has actually a write validation flag (check cifs spec at page 80) but how can this be setted through .NET? There isn't an after-copy validation test as far as I understand through the documented exceptions.

+2  A: 

I would hash the file before and after the copy and then make sure that the hashes are identical.

Matt Wrock
+1 for simple and correct solution.
Sergio Tapia
Hashing the file on the UNC path after the copy, would mean that the file would be copied back. This is not reliable because an error could occur on either of the transfers.
Aggelos Mpimpoudis
You would not have to do a second explicit file transfer. You could just load the file from the remote UNC. In any case an error could occur in the initial transfer of in the file open. So in addition to comparing the hash, you would want to consider an IOException as another criteria of failure.
Matt Wrock
The transfer isn't going to be done explicitly but implicitly (that's for sure). Think about it, you hash a remote file. You DON'T have access to system functions there, the CIFS protocol only does, read / write operations. By calling an integrity checker function with the UNC file as input, isn't the file going to be read across the network? The remote file isn't going to be hashed in the remote system, but in the local execution environment!
Aggelos Mpimpoudis
You are correct. The copy is implicit. You always risk an IOException. While it is not completely reliable, if it does succeed and the hash matches, you have your guarantee that the original copy is reliable.
Matt Wrock
Any sample code, please !!!
alhambraeidos