trapping errors while using FTP.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting trapping errors while using FTP.
# 1  
Old 05-26-2005
trapping errors while using FTP.

Hello,

I have the following shell script to perform ftp:

ftp -n $HOST<<EOD
quote USER $USER
quote PASS $PASS
lcd $outputd
cd $dir
binary
put *.zip
quit
EOD

If any error is generated from this script then how to trap the error. For ex: let's say we entered wrong password then the return code from this shell script is always coming as 0. Even though there is a login error.

Do anybody have an idea how to trap ftp errors?

Appreciate your reply.
Radhika.
# 2  
Old 05-26-2005
Quote:
Originally Posted by radhika

Do anybody have an idea how to trap ftp errors?

Appreciate your reply.
Radhika.
In general you could redirect the output STDOUT and STDERR of the ftp call to a log file and then query the log file for specific success or failure return codes to determine the status of the current ftp session. From this perspective you might have to create different log files for each ftp session and actively manage your logfiles too.

If there is any other way please advise. Thanks. Jerardfjay
# 3  
Old 05-26-2005
Try this:

ftpresults=`ftp -inv $ip_box_name <<EOB
user $userid $password
put $ftp_file $downstream_name
bye
EOB`

ftp_ctr=`echo "$ftpresults" |grep "226" | wc -l`
echo $ftp_ctr
if [ $ftp_ctr = 1 ]
then
echo "FTP of " $file_name " to " $ip_box_name " was successful"
echo " "
else
echo="FTP failed"
fi

Last edited by nimo; 05-26-2005 at 07:17 PM..
nimo
# 4  
Old 05-26-2005
I am sorry, what does $ftpresults have in it.

Is it like stdout and stderr from ftp.sh?
# 5  
Old 05-26-2005
My apology, I forgot part of the script in my editor. Please refer to my previous message for the script again.
nimo
# 6  
Old 05-27-2005
ThankYou!!! All for your ideas and sample code. I am going to try them this morning.

Radhika.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell scripting errors for ftp process

Hi i am facing problem in shell scripting for ftp process getting following errors here is the script & result vi GtpTxnlogs_ftp.sh "GtpTxnlogs_ftp.sh" 40 lines, 921 characters #!/usr/bin/bash ###################################################################################### #... (4 Replies)
Discussion started by: Sarmistha
4 Replies

2. UNIX for Dummies Questions & Answers

FTP no errors but file ZERO SIZED!

Hi guys, First of all this was working and stopped without reason. There is a file that it is transferred from a PC to a Unix machine (RHEL). It is not big, around 9k. The user who performs the transfer has authority to the full path. Furthermore it is the owner of all objects. We use... (8 Replies)
Discussion started by: 300zxmuro
8 Replies

3. Shell Programming and Scripting

trapping sftp errors

I'm trying to trap errors in a shell script executing an sftp command this way: /usr/bin/sftp $FTP_USER@$FTP_SERVER <<EOF> $HOME/$ERR_FILE cd $FTP_DIR put $FILE_NAME bye EOF I expect errors to be recorded in $ERR_FILE but they are not. The only thing in the $ERR_FILE is: sftp> sftp>... (2 Replies)
Discussion started by: pochon
2 Replies

4. Shell Programming and Scripting

trapping errors from a sub call

I want to trap any errors from a backup database script and send an email when an error occurs. I can trap command errors and send an email in the following code. My problem occurs if an error occurs in the Maxl script, /opt/hyperion/AnalyticServices/bin/essmsh < MaxlScript.msh..., that is called... (0 Replies)
Discussion started by: t_coop
0 Replies

5. UNIX for Dummies Questions & Answers

trapping errors

I am using unixs script to submit programs (SQRS) and need to trap any time of error that is received once the job finishes. Examples of the type of errors I am getting Error! SQR Failed To Process mkdir: Failed to make directory These are showing up in a log file but I do not want to... (3 Replies)
Discussion started by: TimHortons
3 Replies

6. UNIX for Dummies Questions & Answers

ftp errors

I'm no Unix expert (so please excuse any misuse of Unix vocabulary or terminology) and I have an issue that is bugging me. I basically have a scheduled task which uploads and then downloads some files for me using ftp. Everything was (mostly) working fine until last week. Suddenly it refuses... (1 Reply)
Discussion started by: Approx.Purified
1 Replies

7. Shell Programming and Scripting

Searching and FTP error trapping

This is gonna sound dumb but... 1 It seems that I cannot use the search function here properly. In researching to find a solution to an FTP error trapping issue, I go to the search option in the forum and use FTP as a search term and ask it to select all forums to search in..... I get no... (2 Replies)
Discussion started by: Bartman
2 Replies

8. Shell Programming and Scripting

How to find out Errors in FTP Scripts

Hi Please let me know is there any way through which I can find out errors & do debugging in FTP scripts. Thanks Sourabh TCS (1 Reply)
Discussion started by: sourabhshakya
1 Replies

9. UNIX for Dummies Questions & Answers

ftp error trapping

I have written a UNIX script that will automatically ftp a file to a server. The problem is when I missed enter information w/in the .txt file that contains the userid/password and what file to transfer, I had no way of capturing the failuer of the file transfer. I verified w/in the script that the... (1 Reply)
Discussion started by: dhawkjrscripter
1 Replies

10. UNIX for Dummies Questions & Answers

ftp error trapping

Hi I'm hoping I could get some help on the following. I'm writing a script which will in turn create an ftp script then excecute it. eg echo "user $user $pass" > $script echo "cd $remote_dir" >> $script echo "bi" >> $script echo "mput $file" >> $script echo "bye" >> $script ftp -n -i $ip... (1 Reply)
Discussion started by: Bab00shka
1 Replies
Login or Register to Ask a Question