Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to trap errors in an ftp script

Status
Not open for further replies.

jboo

Programmer
Jan 4, 2001
12
GB
AIX 4.3 Korn shell. I want to trap ftp errors (e.g. not connected, invalid user name etc) in the following script:

ftp -in <<finished
open REMOTENAME
user USERNAME PASSWORD
cd USERDIRECTORY
put USERFILE
quit
finished

Using the trap command, for all interrupts, doesn't seem to have any affect.
 
I've never seen it done the way you want. Best bet (and what I do) is pipe all output to a file and then check the file once the ftp is finished. Problem is that once you issue the ftp command, the shell has no control until the heredocument is reached.

Greg.
 
'Sright , there's no way to trap, but you can log 'em
Use .netrc files

#!/bin/ksh
ND=&quot;/data/logs/ftps&quot;
echo &quot;machine ${RHOST}
login ${RUSER}
password ${RPASS}
&quot; > ${HOME}/.netrc
chmod 600 ${HOME}/.netrc

echo &quot;cd ftpdatadir&quot; > $ND.tmp
echo &quot;put mscstx11.tx &quot; >> $ND.tmp
echo &quot;bye&quot; >> $ND.tmp

cat $ND.tmp | ftp -i -v ${RHOST} > $ND.out 2>&1
chmod 666 $ND.tmp $ND.out 2>/dev/null


You can then check for &quot;transfer complete&quot; etc in the log file
HTH ;-) Dickie Bird
Honi soit qui mal y pense
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top