problem in exit status of the command in a shell script-FTP

Hi All,

I have developed below script for FTP a file from unix machine to another machine.

ftpToABC ()
{

USER='xyz'
PASSWD='abc'
echo "open xx.yy.zbx.aaa
user $USER $PASSWD
binary
echo "put $1 abc.txt" >> /home/tmp/ftp.$$
echo "quit" >> /home/tmp/ftp.$$
ftp -ivn < /home/tmp/ftp.$$ > /home/temp/ftptraceUnix.$$
if [[$? -ne 0 ]]; then

echo "FTP is failed trying to send the file again"
ftpToABC $1
else
echo "FTP successful.File $1 transferred successfully"
fi

}

Now the problem is even if the file is not transfered it is showing the message as FTP successful. Could you please help me to resolve the problem.

it does a space after the [ ...

if [[ $? -ne 0 ]]; then

Plus I think you will run into a problem here:

echo "open xx.yy.zbx.aaa
user $USER $PASSWD
binary
echo "put $1 abc.txt" >> /home/tmp/ftp.$$
echo "quit" >> /home/tmp/ftp.$$

with the echos following "binary".

Please add code tags.

You are checking ftp's exit status and not the status of the files transfer which is different.
Though a file is not transferred, the execution of the ftp client might successfully end which means $? will return 0 { success } if its not with respect to the application.

So, direct the output of ftp client to a logfile and parse that.