How to check the integrity of a file transferred over the network in Linux and Windows
August 18, 2024
When you need to download or upload large files, you need to check their integrity. For example, when uploading a large file to a hosting or downloading an archive with a backup copy of sites, you need to transfer files of several gigabytes or even tens of gigabytes between computers.
With a slow Internet connection or with speed restrictions on one side or another, as well as with an unstable connection, the question may arise – did the file download (upload) stop because it was completely transferred or because the connection was broken?
The situation is especially unclear when using web interfaces (for example, elFinder (Web file manager)) and various unusual solutions, such as web SSH.
In general, you need to make sure that the copy of the file on the remote computer and on the local computer are identical, what is the easiest way to do this? In this case, we need a guarantee that the file is not damaged even partially, since some files can be opened even in an incomplete form – for example, a video file can be played to the point of interruption, similarly with audio, text and some other files.
The easiest way to ensure the integrity of a file is to find its checksum for its copies. There are various algorithms for calculating checksums – you can choose any, for example, MD5.
How to check that a file is not damaged in Linux. How to check the checksum of a file in Linux
To calculate the checksum using the MD5 algorithm, the md5sum utility is used.
To calculate the checksum of a file named FILE, use the following command:
md5sum FILE
Example of calculating the checksum for the file 20240804_131135.zip (on the local computer):
md5sum 20240804_131135.zip
Example of the output:
b738817e5fa32ba5121e3ebcb7c97190 20240804_131135.zip
That is, the checksum of the specified file is b738817e5fa32ba5121e3ebcb7c97190.
And another calculation of the file checksum, but this time on the web hosting where this file was uploaded:
Since the file hashes match, this reliably confirms that the file was not damaged during transmission.
How to check if a file is not damaged in Windows. How to check a file's checksum in Windows
Windows has pre-installed utilities for calculating file checksums, including using the MD5 algorithm.
You can use the Get-FileHash utility as follows:
Get-FileHash FILE -Algorithm MD5
An example of calculating the MD5 hash for the file 20240804_131135.zip:
Get-FileHash 20240804_131135.zip -Algorithm MD5
The Get-FileHash utility is part of PowerShell and is available on all modern Windows releases.
Another pre-installed utility for calculating file checksums is CertUtil. To calculate MD5 hash with CertUtil use command like:
CertUtil -hashfile FILE MD5
For example:
CertUtil -hashfile 20240804_131135.zip MD5
Related articles:
- How to install John the Ripper and Johnny on Windows with GPU support (77.3%)
- Why does VirtualBox lose connection when changing MAC address (SOLVED) (50%)
- How to download YouTube videos on Windows and Linux (GUI without third party services) (50%)
- How to download YouTube subtitle file in any language (50%)
- Free analogue of Total Commander (50%)
- How to list all Cron tasks (RANDOM - 22.7%)