Operating System - HP-UX
1830231 Members
1745 Online
109999 Solutions
New Discussion

EXIT status of FTP command

 
chinnaga
Advisor

EXIT status of FTP command

Hi All,

I want to get the exit status of FTP command,like if the user name and password is correct. If the file has transfered completely. Based on the success or failure I need to comtinue with the script. I am trying to write in C shell.

Can u please help me.
Thanks in Advance.
5 REPLIES 5
lawrenzo
Trusted Contributor

Re: EXIT status of FTP command

not sure about the C shell however you can direct standard output to a file and just run a check on that file for ftp return codes etc ...

if you run the ftp manually and transfer the file you will have the data you are looking to check.

HTH

Chris.
hello
Dennis Handly
Acclaimed Contributor

Re: EXIT status of FTP command

I'm sure others will tell you that you shouldn't be programming in the scummy C shell.
The posix shell or ksh is superior.
chinnaga
Advisor

Re: EXIT status of FTP command

Any shell would be fine.
Matti_Kurkela
Honored Contributor

Re: EXIT status of FTP command

If you use the standard /usr/bin/ftp command, you cannot evaluate the exit status code of individual FTP protocol commands like "USER" or "PASS" in your script, because the shell will get the exit code only when /usr/bin/ftp exits... thus forcing your FTP session to end. If you pipe several FTP protocol commands to the standard /usr/bin/ftp, you have no way of knowing which of the commands failed when /usr/bin/ftp exits.

You would need your script to run "side by side" with /usr/bin/ftp, reading its output and issuing the appropriate commands. This is hard to do with just a shell script, because /usr/bin/ftp is designed mainly for interactive use. An additional scripting utility like "expect" would make it possible, but using a FTP client with more powerful native scripting features would be even easier.

If you need a FTP transfer solution that can be scripted to handle any errors... may I suggest using a different FTP client instead? The old "Kermit" is no longer a simple modem-based file transfer protocol which it was in the 1980s: it has become a full-featured file transfer suite which supports many protocols.

HP-UX includes C-Kermit 7.0, which can do many things but cannot do FTP. But if you can install C-Kermit 8.0, it contains a built-in FTP protocol, which is fully scriptable using C-Kermit's own very powerful scripting language.

http://www.columbia.edu/kermit/ck80.html
http://www.columbia.edu/kermit/ck80binaries.html#hp

MK
MK
James R. Ferguson
Acclaimed Contributor

Re: EXIT status of FTP command

Hi:

If you are doing FTP commands in a shell script (regardless of the shell --- csh, ksh, bash or Posix) you are going to have to parse the text and/or the three-digit messages that are emitted for each command. See the 'ftpd(1M)' manpages for more on this.

Essentially in a shell script you enable verbose logging ('-v') during the FTP transfer to do this. For instance, you would need to look for something like this in your captured log to signify a succesful file transfer:

226 transfer complete

The actual text may vary with different servers.

You can avoid this pain if you write your FTP scripts in Perl using Perl's 'Net::FTP'. This allows straightfoward logic, like:

$ftp->login() or die "..."

and:

$ftp->put($localf, $remotef) or die "..."

Regards!

...JRF...