I am looking for a way to connect to a remote server with ftp
or lftp
and make sure the following steps:
Copy files from FTP server to my local machine.
Check if the downloaded files are fine (i.e. md5checksum).
If the download was fine then delete the downloaded files from the FTP server.
This routine will be executed each day from my local machine. What would be the best option to do this? Is there a tool that makes abstraction of all the 3 steps ?
I am running Linux on both client and server machines.
Update: Additionally, I have also a text file that contains the association between the files on the FTPserver and their MD5sum. They were computed at the FTP server side.
First, make sure your remote server supports the checksum calculation at all. Many do not. I believe there's even no standard FTP command to calculate a checksum of a remote file. There were many proposals and there are many proprietary solutions.
The latest proposal is:
https://tools.ietf.org/html/draft-bryan-ftpext-hash-02
So even if your server supports checksum calculation, you have to find a client that supports the same command.
Some of the commands that can be used to calculate checksum are:
XSHA1
,XSHA256
,XSHA512
,XMD5
,MD5
,XCRC
andHASH
.You can test that with WinSCP. The WinSCP supports all the previously mentioned commands. Test its checksum calculation function or the
checksum
scripting command. If they work, enable logging and check, what command and what syntax WinSCP uses against your server.Neither the
ftp
(neither Windows nor *nix version) nor thelftp
support checksum calculation, let only automatic verification of downloaded file.I'm not even aware of any other client that can automatically verify downloaded file.
You can definitely script it with a help of some feature-rich client.
I've wrote this answer before OP specified that he/she is on Linux. I'm keeping the Windows solution in case it helps someone else.
On Windows, you could script it with PowerShell using WinSCP .NET assembly.
You can run it like:
This is partially based on WinSCP example for Verifying checksum of a remote file against a local file over SFTP/FTP protocol.
(I'm the author on WinSCP)
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: