i wouldn't recommend using ftp as scp/sftp are much better easier in error handling and offer much better security.
Anyway, I made a while ago an auto-ftp script, find below some hints:
- In fact you should make your script loop untill a success condition is reached, which in this case means all files are transferred successfully.
- In your script, you should save the ftp output and have it checked to ensure last transfer is ok. this is what I came up with:
I just grabbed this code from the source scripts, so it might not be ready for use. it is just to get the idea.
In fact if you could grep ^226 $resultfile |grep -v "226 bytes" it should be a good indication the file is transmitted successfully.
The reason to grep -v "226 bytes" is in case the file is 226 bytes you'll grep
226 bytes transferred (or something like that).
#syntax:
#analyze_ftpresult <ftpresult file>
function analyze_ftpresult
{
# check rfc 959 on
http://www.ietf.org/rfc/rfc0959.txt
#
resultfile=$1
is_error=0
is_noconnect=`fgrep "Not connected" ${resultfile} 2>/dev/null`
is_226=`grep ^"226 " ${resultfile} 2>/dev/null|grep -v ^"${errcode} bytes" 2>/dev/null`
is_250=`grep ^"250 " ${resultfile} 2>/dev/null|grep -v ^"${errcode} bytes" 2>/dev/null`
if [ -z "${is_226}" -a -z "${is_250}" ] ;then
return 1
fi
if [ -n "${is_noconnect}" ] ;then
return 10
fi
${debug} && set +x
# Too much debugging info
for errcode in `echo 421 425 426 450 451 452 500 501 502 503 504 530 550 551 552 553`
do
error=`grep ^"${errcode} " ${resultfile} 2>/dev/null|grep -v ^"${errcode} bytes" 2>/dev/null`
case ${error} in
421|425|426) return 10 ;;
esac
if [ -n "${error}" ] ; then
is_error=`expr ${is_error} + 1`
echo "${stamp} ERROR ${_sfile}: ${error}" >>${somelogfile}
fi
done
${debug} && set -x
return ${is_error}
${debug} && echo "<< end function analyze_ftpresult >>"
}