Advertisement

04.02.2008 at 07:56AM PDT, ID: 23289510
[x]
Attachment Details

Error handling during FTP.

Asked by gram77 in Linux, Unix Operating Systems

I have been asked to handle errors arising from ftp.

This code does not handle errors.

if test $# -ne 3
then
        echo "Usage: $0 <PROCESSING_DIR> <CURRENT_DIR> <FTP_DIR>"
        exit 1;
fi

process_dir=$1
current_dir=$2
ftp_dir=$3

cd $process_dir

ls CSH*.HIST > $current_dir/temp_file.txt
ls BSH*.HIST >> $current_dir/temp_file.txt
ls DSH*.hist >> $current_dir/temp_file.txt

cat $current_dir/temp_file.txt | \
while read line
do
wc -c $process_dir/$line > $current_dir/temp.txt
file_size=`awk '{print $1}' $current_dir/temp.txt`

 if [[ $file_size > 0 ]]; then  ##error needs to be handled from here.
    echo "
       user USERNAME PASSWORD
       lcd $process_dir
       bin
       prompt
       cd $ftp_dir
       mput $line
       bye
         " | ftp -ivn mopppgstrtadm6.pfizer.com
    echo "PDMA files successfully transferred to startrak."
 else
    echo "$line is a 0 byte PDMA file."
 fi
done   ##error needs to be handled till here.

rm -f  $current_dir/temp.txt
rm -f  $current_dir/temp_file.txt

I wish to replace the ftp code with this code:


 if [[ $file_size > 0 ]]; then  ##error needs to be handled from here.
    echo "
       user ibmpdma st4rtr4k!pdm4
       lcd $process_dir
       bin
       prompt
       cd $ftp_dir
       mput $line
       bye
         " | ftp -ivn mopppgstrtadm6.pfizer.com >> $LOG_FILE

      # testing the exit status of FTP
      egrep "Transfer complete" $LOG_FILE >/dev/null
      if [ $? = 0 ]
      then
         echo >> $LOG_FILE
         echo "FTP Successfully Done" >> $LOG_FILE
      else
         echo >> $LOG_FILE
         echo "FTP UnSuccessfull" >> $LOG_FILE
         exit 1
      fi

 else
    echo "$line is a 0 byte PDMA file."
 fi

but this code does not identify reason for failure:

I want to have something like FTP UnSuccessful due to:
1.non availability of space on the ftp server. or
2.incorrect username/password while logging into the ftp server. or
3.lcd and cd path not available.

How is this possible:


USERNAME AND PASSWORD REPLACED
Vee_ModStart Free Trial
 
Loading Advertisement...
 
[+][-]04.02.2008 at 12:06PM PDT, ID: 21266296

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: Linux, Unix Operating Systems
Sign Up Now!
Solution Provided By: MikeOM_DBA
Participating Experts: 2
Solution Grade: A
 
 
[+][-]04.02.2008 at 02:24PM PDT, ID: 21267686

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_EXPERT_20070906