Friday, July 23, 2010

FTP in UNIX with Error Handling

Here is the script to handle FTP in UNIX. It also includes error including.

unix command $? will not capture error status, so error message has to be written to a logfile and then read.

error_log=/tmp/error_log.log
lc_server_name="your.ftp.server.name"
echo "1" $lc_server_name
ftp -i -n -d<<EOF >$error_log
open $lc_server_name
user userid password
bye
EOF
result=`grep -c 'Not connected.' error_log.log`
result1=`grep -c 'Login failed.' error_log.log`
echo $result
echo $result1
if [ ${result} -gt 0 -o ${result1} -gt 0 ]; then
echo "Connect to FTP failed"
else
echo "Connection Successful"
fi

No comments:

Post a Comment