below is my code , but for some reason the return part is not working, only file transfer is happening and no exit status is checked .please me help me to fix this code
#!/bin/sh
#set -vx
ftp -nv sitelocation << !
user username password
lcd localdir
cd /remote dir
mget *.*
close
bye
!
return_code=$?
echo $return_code
case "$return_code" in
0)
echo " "
date +"File transfer successfully at %T on %D"
exit 0;;
esac
echo " "
date +" File transfer failed at %T on %D"
exit 1;
The return code of ftp is always 0 because it is just returning that it has been successfully called. The internal return codes of ftp like for example:
200 PORT command successful
can't be cought outside ftp by evaluating $?. This could achieved by parsing the log of the ftp session for example. Maybe scp is an alternative for you too. It is key based, encrypted and you can immediately check $?.
---------- Post updated at 10:17 AM ---------- Previous update was at 10:16 AM ----------
I added his missing ! and reformatted the code since he said the ftp itself worked. Just as side note.