I have a task in which I want to handle error occurred in FTP downloading, For which I used the wget
command to download a file via FTP and once the download is complete, compare downloaded filesize with FTP file size.
For that, I have the code as follows. My question: is this the correct method?
# fetch file details from the server and extract only number from the return value
FileSizeOnServer=curl --max-time 10 -u $FTP_USER:$FTP_PASSWORD --head $FTP_Path 2>&1 | grep "Content-Length:"
echo "Present File Size Details:" $FileSizeOnServer
FTP_File_Size=${FileSizeOnServer#*: }
echo "FTP_File_Size:$FTP_File_Size"
# fetch only size of local file size
DownloadedFileSize=`stat -c %s /home/pi/Desktop/ABCD.txt`
echo "DownloadedFileSize:$DownloadedFileSize"
# compare local and ftp file size
if [ "$DownloadedFileSize" -eq "$FTP_File_Size" ]; then
echo "Size matched"
else
echo "File Size doesn't match Start Downloading again"
fi