Operating System - HP-UX
1755344 Members
5631 Online
108831 Solutions
New Discussion юеВ

ftp return values from within shell scripts

 
Rick Taylor
Occasional Contributor

ftp return values from within shell scripts

Is there a way to retrieve the return code from ftp from within a korn shell?
If its worth doing at all, its worth doing well!
4 REPLIES 4
Andreas Voss
Honored Contributor

Re: ftp return values from within shell scripts

Hi,

return code is difficult.
What about logging the error output of the ftp command ?
Just redirect with 2>/tmp/ftperr.log
an look then for any contents in it
(
if [ ! -s /tmp/ftperr ]; then
#your error actions
fi
).
If it is empty the ftp should be successfully.

Regards

Andrew
Rick Garland
Honored Contributor

Re: ftp return values from within shell scripts

You could write a perl or C program but redirecting to a log file would be easiest and give you all info concerning the ftp process that took place. Of course, what is captured in the log file depends on what you are redirecting.
James R. Ferguson
Acclaimed Contributor

Re: ftp return values from within shell scripts

Rick:

My experience is the same as Andreas & Rick.

I run my ftp scripts with the verbose option (-v) and tee or redirect output to a logfile. I also like to use the 'hash' mark to record progress.

The intermediate and final replys of the ftpd are recorded as 3-digit values (see: man ftpd) in the redirected output log, along with an textual translation. You could awk to isolate key values like "226" which denotes a successful transfer.

Depending on the server to which you connect (UNIX, NT, etc.) the text associated with the value may differ. For instance, #226 is "Transfer complete" as well as "Transfer finished successfully.".

If you are doing 'gets', the presence of a file can be used to signal a "successful" ftp.

Needless to say, none of this is direct.

...JRF...

...JRF...
RikTytgat
Honored Contributor

Re: ftp return values from within shell scripts

Hi,

I've done somthing like that.

The script is in attachment.

It is part of a bigger script, but the stuff you want to do is in there.

Bye,
Rik