Operating System - HP-UX
1849495 Members
6867 Online
104044 Solutions
New Discussion

Re: Capturing ftp status codes in a UNIX script

 
Christopher Andrada
New Member

Capturing ftp status codes in a UNIX script

I need to capture ftp status codes during ftp implementation inside a unix script.

Hv tried using the command line

ftp -n < (ftp.template) >> (target.file)

but seems that this is not capturing the step by step implementation of the ftp process

during a successful transmission, only the below status was captured

200 UMASK set to 022 (was 027)

this is just one of the commands I have used inside the ftp template.

But I also need to capture the status

226 Transfer complete.

How should I do this??

---Many thanks for the advise.
3 REPLIES 3
Sridhar Bhaskarla
Honored Contributor

Re: Capturing ftp status codes in a UNIX script

Not sure if I quite understand your problem. You can try with verbose output to see if you are getting what you need.

ftp -v -n < ftp.template >> target_file

-Sri
You may be disappointed if you fail, but you are doomed if you don't try
Gregory Fruth
Esteemed Contributor

Re: Capturing ftp status codes in a UNIX script

You can do it in Perl quite easily:

use Net::FTP;
$ftp = Net::FTP->new('foo.bar.com');
$ftp->login('username','password');
$ftp->cwd('/pub');
$code = $ftp->code;
print("return code is $code\n");
$ftp->quit;
Jay Newman
Frequent Advisor

Re: Capturing ftp status codes in a UNIX script

The following works:
ftp -n -v <(ftp script) >>(output file)
But what I would really recommend, is :
ftp -n -v <(ftp script) >>(output file) 2>&1

The "-v" tells ftp to display verbose output.
" 2>&1 " directs your standard error to the same place as your standard output. A good idea in case anything ever breaks.
"Success is defined by getting up one more time than you fall down."