FTP upload

Hi All,

I am new to this forum and i need help from you .

Here i want to get a mail conformation when ever the file was uploaded to FTP server.Here is my FTP script . Can any one plz help me how to get a mail confirmation weather the file was uploaded or not.

#!bin/sh

HOST='192.168.2.85'
USER='ddd'
PASSWD='dfd'

#FILE='*'

#DT=$(date +%a_%h_%d_%Y)
DT=$(date +%Y-%m-%d)

ftp -n $HOST > .ftpout.txt 2>.ftperr.txt <<END_SCRIPT

quote USER $USER
quote PASS $PASSWD

#lcd /home/oracle/test
lcd /u03/APDEXTS/

mkdir TEST
cd TEST
mkdir $DT
cd $DT

prompt
mput *.cec
quit

END_SCRIPT
exit 0

Thanks & Regards,
Pooran Prasad.

After the END_SCRIPT

if [ "$?" eq "0" ] 
then
    echo "FTP operation Successful" | mail -s "Success :: FTP Status" abc@xyz.com
else
    echo "FTP operation Failed" | mail -s "Failure :: FTP Status" abc@xyz.com
fi

Hi,

I have added the below code in my script and when the file was uploading we are getting success mail and even when the file was not uploaded also we are getting the same success mail .

Here I changed my ftp server ip and tried to run the script but i am getting success mail only.

Here is my script.

#!bin/sh

HOST='192.168.2.85'
USER='ss'
PASSWD='ss'

#FILE='*'

#DT=$(date +%a_%h_%d_%Y)
DT=$(date +%Y-%m-%d)

ftp -n $HOST > .ftpout.txt 2>.ftperr.txt <<END_SCRIPT

quote USER $USER
quote PASS $PASSWD

#lcd /home/oracle/test
lcd /u03/APDEXTS/

#mkdir APD_TEST
#cd APD_TEST
#mkdir $DT
#cd $DT

prompt
mput *.cec
quit

END_SCRIPT

if [ "$?" = "0" ]
then
    echo "FTP operation Successful" | mail -s "Success :: FTP Status" user@somewhere.com
else
    echo "FTP operation Failed" | mail -s "Failure :: FTP Status" user@somewhere.com
fi

exit 0

Thanks & Regards,
Poorna Prasad.S

I don't think this will work out, ftp command will always end successfully after you enter quit at ftp prompt. How could you check the exit status of ftp command to identify whether the file transimission was successful.

It won't work as far as i have tested. The proper way is to check the ftp logs and check for the error code in the log. You have checck for error codes starting from 300 - 599 for any errors.

Please try this, add the below line before the if condition and just after the END_SCRIPT,

grep -e "^5[0-9][0-9]" -e "^4[0-9][0-9]" .ftperr.txt

I see, then probably we need to check the log file as mentioned by the kumaran

thanks for the info