How to track exit status of ftp automation

ftp automation code is

ftp -v -n -i $host_name << EOF
user $u_name $u_pass
bi
mput $tar_file
bye
EOF

How to check whether the file is successfully transfered or not. Suppose the user name or password is provided wrongly then the code should track the error and ask the end user to enter username and password again.

You can store the output of you ftp command to some file like below

ftp -v -n -i $host_name > ftp.log << EOF
user $u_name $u_pass
bi
mput $tar_file
bye
EOF

then check the ftp.log like

cnt=`grep -c "Transfer complete" ftp.log`
if [ $cnt -eq 0 ]
then
cnt1=`grep -c "logged in" ftp.log`
if [ $cnt1 -eq 0 ]
then
echo "Invalid username or password"
else
echo "FTP failed"
fi
fi

thanks a lot ranjith, its working fine.