ftp check for failed attempts

Hi,

I have created the below ftp script to put files over to our capacity server, the check at the end works if ftp fails to run however if the script cannot login or the transfer itself failed there is no warnings.

Does anyone know the syntax to trap the erorr codes or to put a check within FTP?

Thanks a million ....

# create an ftp script to move the data to sftp

    echo "ftp -v -i -n $SERV <<!EOF" > $FTP
    echo "user capacity.ftp C@p@C1ty" >> $FTP
    echo "binary" >> $FTP
    echo "prompt" >> $FTP

# Find the processed nmon file to be sent to capacity server for processing:

cd $OUTDIR
PDATE=`perl -le '($year,$mon,$day,$hrs,$min)=(localtime(time()-$ARGV[0]))[5,4,3,2,1];printf "%04d%02d%02d_%02d\n",$year+1900,$mon+1,$day,$h
rs,$min' 3600`
TFILE=`ls ${NFILE}_${PDATE}*.csv`

            if [ -f $\{OUTDIR\}/$\{TFILE\} ] ; then

                    continue

            else

                    logfile "$TFILE is not available for transfer, please investigate and transfer the file."
                    exit 1
            fi


    echo "mput $TFILE" >> $FTP
    echo "$DATE:$TIME//Transfering $TFILE to $SERV " >> $PROGLOG
    echo "!EOF" >> $FTP
    chmod 777 $FTP

#$FTP

    if [ $? -ne 0 ] ; then

            logfile "failed to FTP $TFILE to $SERV"
    fi

In my code I have directed the output of the ftp process to a file and then interrigate the file for verbage.

ftp $rmthost <<COMMANDS>> $ftplog 2>&1

checkftp=`grep -c "Transfer complete" $ftplog`
if (($CHECKFTP > 0 )); then
mailx -s "error" me@mymailaddress < $ftplog
else
echo "ftp ok" > $joblog
fi

take a peek here

groovey!

thanks both for your help :slight_smile: