Unix FTP exit code help!?

I have a script which uses ftp to connect to another machine and put some files. the script then deletes the old files. However should the ftp connection fail (i.e if the username or password is changed) then the files should not be deleted. I am using the script below but it doesn't work. can anyone... show more I have a script which uses ftp to connect to another machine and put some files. the script then deletes the old files. However should the ftp connection fail (i.e if the username or password is changed) then the files should not be deleted. I am using the script below but it doesn't work. can anyone suggest why or an alternative? (PS I know it's not good to have the username/password hardcoded in the script):

#!/bin/sh

USER=user1
PASSWD=password1

if ftp -n -v ip.address <<SCRIPT
user $USER $PASSWD
binary

FTP ACTIONS

quit

SCRIPT
then
echo "***** SUCCESSFUL *****"
else
echo "FAILED FAILED FAILED"
fi
3 answers 3