tags:

views:

132

answers:

1

I'm implementing a .NET utility to sync my local folder with an FTP location. What is the best way to check whether the file is the same or not. I'm using a ,NET FTP Client API called 'edtfptnet'. I found that even though files are the same, the sizes are shown different for exe files. The size returned by the API is the same as the size of the file shown by FileZilla. But it is different from the size obtained by FileInfo.Length. Both these values are different from the size shown in file properties by the windows explorer. Why does this happen? This doesn't happen for text files.

Is there any other way to quickly check whether the file is same or not. The access times are different. The API gives only Last Modified Time, which is different from the last write time.

+1  A: 

Usually if the size and modification time of both files are the same, they can be assumed to be identical. I am not familiar with the edtfptnet client, but for identical files the remote file size should equal the FileInfo.Length which should definitely equal the size reported by Windows Explorer (make sure you looking at "Size:" and not "Size on disk:"), except on esoteric operating systems such as VMS (where files are reported in 512 increments, or "blocks", regardless of the actual file size).

In order to be certain that the files are identical, you need to compute and compare a hash for each file. Some FTP server support the XCRC command, which does a server-side computation of the file's CRC32 hash, which you can then compare to the CRC32 hash you computed for your local file (e.g. this post). But this needs to be done in addition to comparing the file sizes.

Allon Guralnek