1832935 Members
2870 Online
110048 Solutions
New Discussion

Re: ftp scripting,

 
SOLVED
Go to solution
Admin.SIF
Frequent Advisor

ftp scripting,

Hi all,
How to get back the pid of a background process (script ftp) in a variable to follow it by program ?
We need to know the result of the ftp to continue because the session remains hung on even if it is inactive.
Thanks,
Nora
Sysd. Amin. Inforef
9 REPLIES 9
A. Clay Stephenson
Acclaimed Contributor

Re: ftp scripting,

If I understand your question $! is the pid of the last background process.
If it ain't broke, I can fix that.
James R. Ferguson
Acclaimed Contributor

Re: ftp scripting,

Hi:

The 'ftp' session doesn't return an exit value denoting success or failure, and that can make scripting to find the success or failure of a session a bit of a pain.

If you really want to decipher success/failure you can parse the three-digit numbers included with the reply from each ftp command. To do this in an ftp script, you can redirect verbose output into a logfile and parse the replys. See "man 1M ftpd" for a discussion of the format of the reply messages.

...JRF...
someone_4
Honored Contributor

Re: ftp scripting,

Hello,
Please Mr Clay correct me if I am wrong but if you do
#./script &
it gives you the pid when it is executed in the background. It gives me the same pid that
$! gives me. But the output says
sh: 27138: not found. Is that what it is supposed to do ?

Richard
James R. Ferguson
Acclaimed Contributor

Re: ftp scripting,

Hi:

See this recent thread for a discussion of tracking background processes:

http://forums.itrc.hp.com/cm/QuestionAnswer/1,1150,0xfe7387dc4d7dd5118ff00090279cd0f9,00.html

...JRF...
Kevin Wright
Honored Contributor

Re: ftp scripting,

once you send it to the Bg, use jobs -l to get the PID. you could sleep for 30 seconds or so to see if it is hung, and if so kill it.
David W Damon
New Member

Re: ftp scripting,

Hi Admin,
I have solved my ftp problems with a script that I have
included with this reply. The server, user, and password are located in a file in /etc/local directory and is into the
script upon startup.

Hope this helps
A. Clay Stephenson
Acclaimed Contributor

Re: ftp scripting,

Hi Nora:

When I have to do ftp scripting these days, I use perl with the Net::FTP module (available for download at www.perl.org/CPAN). It really makes FTP operations very simple. Any error conditions and timeouts are easy to test for and set. It you don't know perl, now would be a good time to learn.

It's usually something as simple as this (with error checking omitted):

use Net::FTP;

$ftp = Net::FTP->new("remotehost.name", Debug => 0);
$ftp->login("anonymous",'cstephen@xxx.com');
$ftp->cwd("/downloads");
$ftp->get("testfile.txt");
$ftp->quit;


Clay
If it ain't broke, I can fix that.
Admin.SIF
Frequent Advisor

Re: ftp scripting,

Thanks to all for your answers,
The script ftp is included in a .ksh. After the ftp, we have a program which should test the result of the transfer: the contents of the source and the destination. But when there are problems during the transfer, the connection is closed but we have an ftp without connection (equivalent of ftp > prompt with closed connection). We have the errors in a file which we read in a while and as soon as we have an error, we want let us stop the session and manage the end of the program. To do it, it is necessary to us to have the PID of the process FTP to be able to kill the process. The ftp is constructed dynamically and looks like :

ftp -i -v -n server result 2> errors

toto contains the commands ftp like :
user username password
cd ...
get ...
...
bye

Suggestion ?
Nora
Sysd. Amin. Inforef
Wodisch
Honored Contributor
Solution

Re: ftp scripting,

Hello Nora,

why don't you just issue the follwing line from within
your ftp-script:
!echo $PPID > /tmp/fpt.pid

Then you do have the PID available...

HTH,
Wodisch