| |
Verify that the contents of a file on the local system are the
same as the specified file on the server.
Syntax
object.VerifyFile( LocalFile,
RemoteFile, [Options] )
Parameters
- LocalFile
- A string that specifies the name of the file on the local
system.
- RemoteFile
- A string that specifies the name of the file on the
server. If there is an active connection to a server, this must
specify a valid file path on the server. If there is no active
connection, this parameter may be a URL and a temporary connection
will be established to retrieve information about the specified
file.
- Options
- A numeric bitmask which specifies the options that may be used
when comparing the files. This argument may be any one of the
following values:
| Value |
Description |
| ftpVerifyDefault |
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. |
| ftpVerifySize |
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. |
| ftpVerifyCRC32 |
Files are verified by calculating a CRC-32 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. |
| ftpVerifyMD5 |
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. |
| ftpVerifySHA1 |
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
A value of zero is returned if the operation was successful,
otherwise a non-zero error code is returned which indicates the cause
of the failure.
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 SHA-1 hash, MD5 hash, a CRC-32 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.
See Also
GetFile Method,
GetFileSize Method
|
|