ftp Return Code [message #247544] |
Tue, 26 June 2007 05:51 |
Imran_Chennai
Messages: 22 Registered: June 2007 Location: CHN,INDIA
|
Junior Member |
|
|
Hi,
Can any 1 pls say how to get the ftp return code,
I want to call a procedure based on the ftp (success/failure)
In my case ftp returns 0 in though it fails.
FYI my code is
#-------------------------
ftp -i -n -v $HOST >> ${LOGFILE} << EOF
user ... ...
ascii
lcd ${OUTBOUND_DIR}
put ${src_fname}
quit
EOF
#-------------------------
Thanx in advance
Imran | Chennai | India
|
|
|
Re: ftp Return Code [message #247610 is a reply to message #247544] |
Tue, 26 June 2007 09:44 |
ThomasG
Messages: 3212 Registered: April 2005 Location: Heilbronn, Germany
|
Senior Member |
|
|
It's in $? just after the command finishes, so you can there assign it to another variable.
Example :
ftp -i -n -v $HOST >> ${LOGFILE} << EOF
user ... ...
ascii
lcd ${OUTBOUND_DIR}
put ${src_fname}
quit
EOF
retcode=$?
echo "Exitcode FTP :${retcode}"
|
|
|
|
|
|
Re: ftp Return Code [message #247905 is a reply to message #247623] |
Wed, 27 June 2007 08:31 |
ThomasG
Messages: 3212 Registered: April 2005 Location: Heilbronn, Germany
|
Senior Member |
|
|
I just need the return code
Well, when the FTP program itself doesn't provide a > 0 return code for errors during the transfer, your're out of luck in that regard.
|
|
|
Re: ftp Return Code [message #248026 is a reply to message #247905] |
Wed, 27 June 2007 16:47 |
andrew again
Messages: 2577 Registered: March 2000
|
Senior Member |
|
|
This is from an old post I no longer find on the web...
--===================================================
Does anyone have an example of a UNIX ftp script that verifies the file was completly received from the remote machine?
--===================================================
After spending most of the day trying an elegant solution, I settled on this one. This is a section of the code.
echo "ftp -n -v << *EOI" > $SCRIPT/ivr_call_detail_ftp.ksh
echo "open 172.21.102.231" >> $SCRIPT/ivr_call_detail_ftp.ksh
echo "user peri peri;" >> $SCRIPT/ivr_call_detail_ftp.ksh
echo "ascii" >> $SCRIPT/ivr_call_detail_ftp.ksh
echo "cd DOWrptfiles" >> $SCRIPT/ivr_call_detail_ftp.ksh
echo "ls -ltr" >> $SCRIPT/ivr_call_detail_ftp.ksh
echo "get $CALL_FILE ivr_call_detail_$DATE_STAMP.dat" >> $SCRIPT/ivr_call_detail_ftp.ksh
echo "bye" >> $SCRIPT/ivr_call_detail_ftp.ksh
echo "*EOI" >> $SCRIPT/ivr_call_detail_ftp.ksh
chmod 750 $SCRIPT/ivr_call_detail_ftp.ksh
$SCRIPT/ivr_call_detail_ftp.ksh > $LOG/ivr_call_detail_ftp.log
#Get the row from the ls -ltr command that
#contains the remote file and awk for the size.
#Peri is the owner of the file. CALL_FILE is
# the name of the remote file.
RMT_FILE_SIZE=`awk '($3=="peri") && ($9 == "$CALL_FILE") {print $5}' $LOG/ivr_call_detail_ftp.log`
echo "Remote File Size: $RMT_FILE_SIZE."
#Get the row from the ls -ltr command that
#contains the local file and awk for the size.
LCL_FILE_SIZE=`ls -ltr $DATA/ivr_call_detail_$DATE_STAMP.dat | awk '{print $5}'`
echo "Local File Size: $LCL_FILE_SIZE."
if (($LCL_FILE_SIZE == $RMT_FILE_SIZE))
then
echo "FTP Successful."
else
echo "FTP Failed."
fi
|
|
|
Re: ftp Return Code [message #248315 is a reply to message #248026] |
Thu, 28 June 2007 11:05 |
Imran_Chennai
Messages: 22 Registered: June 2007 Location: CHN,INDIA
|
Junior Member |
|
|
Fantastic Andrew...
The logic is great...
Due to lack of time i did it with another concept
copying FYI...
ftp_result1=`grep -c '226 transfer complete' ${LOG_FILE}`
ftp_result2=`grep -c '250 Transfer complete' ${LOG_FILE}`
ftp_result3=`grep -c '530 Login incorrect' ${LOG_FILE}`
ftp_result4=`grep -c 'No such file or directory' ${LOG_FILE}`
ftp_result5=`grep -c '226 Transfer complete' ${LOG_FILE}`
if (( ftp_result3 > 0 ))
then
print -u1 "FTP failed on login \n"
exit -1
fi
if (( ftp_result4 > 0 ))
then
print -u1 "File not found to FTP \n"
exit 0
fi
if (( ftp_result1 == 0 && ftp_result2 == 0 && ftp_result5 == 0 ))
then
print -u1 "FTP failed \n"
exit -1
fi
Thanks
Imran
|
|
|