CFtpClient::VerifyFile Method  
 
BOOL VerifyFile(
  LPCTSTR lpszLocalFile,  
  LPCTSTR lpszRemoteFile,  
  DWORD dwOptions  
);

The VerifyFile method attempts to verify that the contents of a file on the local system are the same as the specified file on the server.

Parameters

lpszLocalFile
A null-terminated string which specifies the file on the local system the remote file will be validated against. The file pathing and name conventions should follow Windows conventions. It is permitted to include environment variables in the local path by surrounding the variable with percent (%) symbols. Local file paths may also use standard file URLs.
lpszRemoteFile
A null-terminated string which specifies the file on the server that will be validated. The file naming conventions must be that of the host operating system. It is permitted to use a URL as the remote file name as long as the server name and port number match what was used to establish the connection.
dwOptions
Specifies the options that may be used when comparing the files. This parameter may be one or more of the following values:
Value Description
FTP_VERIFY_DEFAULT File verification should use the best option available based on the available server features. If the server supports the XSHA1 or XMD5 command, the method will calculate an SHA-1 or MD5 hash of the local file contents and compare the value with the file on the server. If the server does not support either hash algorithm, but it does support the XCRC command, the method will calculate a CRC32 checksum of the local file contents and compare the value with the file on the server. If the server does not support any hash or checksum commands, the method will compare the size of the local and remote files.
FTP_VERIFY_SIZE Files are verified by comparing the number of bytes of data in the local and remote files. This is the least reliable option, and should only be used if the server does not support either the XSHA1, XMD5 or XCRC commands.
FTP_VERIFY_CRC32 Files are verified by calculating a CRC32 checksum of the local file contents and comparing it with the value returned by the server in response to the XCRC command. This option should only be used if the server does not support the XSHA1 or XMD5 commands.
FTP_VERIFY_MD5 Files are verified by calculating an MD5 hash of the local file contents and comparing it with the value returned by the server in response to the XMD5 command. This option should only be used if the server does not support the XSHA1 command.
FTP_VERIFY_SHA1 Files are verified by calculating an SHA-1 hash of the local file contents and comparing it with the value returned by the server in response to the XSHA1 command. This is the preferred option for performing file verification.

Return Value

If the method succeeds, the return value is non-zero. If the method fails, the return value is zero. To get extended error information, call GetLastError.

Remarks

The VerifyFile method will attempt to verify that the contents of the local and remote files are identical using one of several methods, based on the features that the server supports. Preference will be given to the most reliable method available, using either an MD5 hash, a CRC32 checksum or comparing the size of the file, in that order.

The method used to verify a file's contents determines how confidently it can be said that the local and remote files are identical. This method supports several algorithms, listed below in order of preference based on reliability and availability:

  • SHA-1 is a cryptographic hash function that produces a 160-bit (20-byte) hash value. It is the most reliable option supported by this function and is preferred for verifying file contents. Although no longer recommended for cryptographic security due to potential collision attacks, it remains well-suited for file integrity checks where the threat of intentional tampering is low.
  • MD5 generates a 128-bit (16-byte) hash and is faster than SHA-1. It offers a reasonable balance between performance and reliability for non-security-critical applications such as file verification. However, it is less resistant to collisions and should be used only if SHA-1 is not supported by the server.
  • CRC32 is a non-cryptographic checksum algorithm that produces a 32-bit value. It is designed for detecting accidental data corruption rather than verifying content integrity. CRC32 is significantly faster but also far more prone to collisions, and should only be used when stronger methods like SHA-1 or MD5 are unavailable.
  • If none of the supported hash or checksum commands are available, the function falls back to comparing the local and remote file sizes. This is the least reliable method and can only detect differences in file length, not in actual content.

It is not recommended that you use this method with text files because of the different end-of-line conventions used by different operating systems. For example, a text file on a Windows system uses a carriage-return and linefeed pair to indicate the end of a line of text. However, on a UNIX system, a single linefeed is used to indicate the end of a line. This can cause the VerifyFile method to indicate the files are not identical, even though the only difference is in the end-of-line characters that are used.

Requirements

Minimum Desktop Platform: Windows 7 Service Pack 1
Minimum Server Platform: Windows Server 2008 R2 Service Pack 1
Header File: cstools12.h
Import Library: csftpv12.lib
Unicode: Implemented as Unicode and ANSI versions

See Also