I am using FtpClient of Apache Commons Net to upload videos to FTP server. To check if the file has really been successfully transferred, I want to calculate the checksum of remote file, but unfortunately I found there is no related API I could use.
My question is: Whether there is a need to calculate file checksum in ftp server?
If the answer is yes, how to get checksum in FtpClient?
If the answer is no, how do FtpClient know if the file has really been successfully and completely transferred?
Just a addition of how I implemented this. When dealing with standard ftp servers without any additionak modules loaded for checksum checking, all i did was creating a list of MD5 CRC hashes about each file into an SFV file. Say its called uploads.sfv (just in the same format as sfv generator would do). This allows you to do further checksum checks.
Examples about the server side support checksum checking support:
Of course as @MartinPrikryl highlighted, none of these are standardized.
That's a long shot, but if the server supports php, you can exploit that.
Save the following as a
php
file (say,check.php
), in the same folder as yourname_of_file.txt
file:Then, visit the page
check.php
, and you should get the md5 hash of your file.Related questions:
With FTP, I'd recommend to verify the upload, if possible.
The problem is that there's no widespread standard API for calculating checksum with FTP.
There are many proposals for checksum calculation command for FTP. None were accepted yet.
The latest proposal is:
https://tools.ietf.org/html/draft-bryan-ftpext-hash-02
As a consequence, different FTP servers support different checksum commands, with a different syntax.
HASH
,XSHA1
,XSHA256
,XSHA512
,XMD5
,MD5
,XCRC
, to name some. You need to check what, if any, your FTP server supports.You can test that with WinSCP. The WinSCP supports all the previously mentioned commands. Test its checksum calculation function or
checksum
scripting command. If they work, enable logging and check what command and what syntax WinSCP uses against your server.Then execute the command using Apache Commons Net
sendCommand
method:(I'm the author of WinSCP)
If your server does not support any of the checksum commands, you do not have many options: