Hi, Im having a problem with a bash script i am attemping to create a script that connects by FTP downloads all .log files and then checks that the download was successful by trapping error codes, if successful I then want to reconnect to the FTP site and delete the remote files that were transfered to the local machine.

This is my first attempt at any kind of unix scripting so apologies if the answer is obvious

ip_address=xxx.xxx.xx.xx
ip_user=username
#Password needs to be passed in not hardcoded but will change later
ip_pass=password
ftp_mode=binary
logfile=tempfile.log
ftpworked=n

#ignore signals
trap "" 1 2 3 15

echo "FTP Connection Settings ->"
echo "--------------------------"
echo "ftp host : ${ip_address}"
echo "ftp user : ${ip_user}"
echo "ftp password : !!!!!!!!"
echo "ftp mode : ${ftp_mode}"
echo "ftp logfile : ${logfile}"
echo "Start Time : $(date)"
echo "--------------------------"

#run ftp command

ftp -n -v ${ip_address} <<-EOFtp >${logfile} 2>&1
user ${ip_user} ${ip_pass}
${ftp_mode}
prompt off
mget *.log
bye
EOFtp

#trap ftp code

awk ' BEGIN{
#list of standard ftp error codes
ftperr[202]="Command not implemented"
ftperr[421]="Service not available,closing control connection"
ftperr[426]="Connection closed, transfer aborted"
ftperr[450]="File unavailable(e.g. file busy)"
ftperr[451]="Requested action aborted, local error in processing"
ftperr[452]="Requested action not taken. Insufficient storage space in system"
ftperr[500]="Syntax error, command unrecognized"
ftperr[501]="Syntax error in parameters or arguments"
ftperr[502]="Command not implemented"
ftperr[503]="Bad sequence of commands"
ftperr[504]="Command not implemented for that parameter"
ftperr[530]="User not logged in. Check username and password"
ftperr[550]="Requested action not taken. File unavailable"
ftperr[552]="Requested file action aborted, storage allocation exceeded"
ftperr[553]="Requested action not taken. Illegal file name"
ftperr[999]="Invalid Command"
ftperr[777]="Unknown host"
ftperr[666]="A file or directory not exist"
#ftperr[226]="Transfer Complete"
ecode="000"
FOUND="F"
}
{
#check for error code
for ( i in ftperr)
{
if ( i == $1 )
{
ecode=$1
FOUND="T"
}
else if ( $0 ~ /Invalid/ )
{
ecode="999"
FOUND="T"
}
else if ( $0 ~ /Unknown host/ || $0 ~ /Not connected/ )
{
ecode="777"
FOUND="T"
}
else if ( $0 ~ /not exist/ || $0 ~ /No such/ )
{
ecode="666"
FOUND="T"
}

if ( FOUND == "T" )
{
exit;
}
}
}END {
if ( ecode <> "000" )
print ecode ":FTP Successfully done"
ftp -n -v ${ip_address} <<-EOFtp >${logfile} 2>&1
user ${ip_user} ${ip_pass}
${ftp_mode}
prompt off
mdelete *.log
bye
EOFtp
else
print ecode ":"ftperr[ecode]
}' ${logfile}