Operating System - HP-UX
1821544 Members
2444 Online
109633 Solutions
New Discussion юеВ

Re: FTP script not complete

 
SOLVED
Go to solution
Jeff Daigle
Advisor

FTP script not complete

Hello, I am new but learning to write shell scripts- thanks for any help. Attatched is my script that attempts to ftp a file from server1 to server2. When it is run, the 'ftp' command runs, but on the screen it enters 'ftp' mode and waits for my manual input- instead of the scripts entering the rest of the commands. Any help is greatly appreciated. Jeff
6 REPLIES 6
A. Clay Stephenson
Acclaimed Contributor

Re: FTP script not complete

Hi Jeff:

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'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@abc.com');
$ftp->cwd("/downloads");
$ftp->get("testfile.txt");
$ftp->quit;

Believe me, I used to do it in script but this is much cleaner.

Regards, Clay
If it ain't broke, I can fix that.
James R. Ferguson
Acclaimed Contributor

Re: FTP script not complete

Hi Jeff:

Change the line 'ftp' to 'ftp -i -n'.

Regards!

...JRF...
Satish Y
Trusted Contributor
Solution

Re: FTP script not complete

Hi Jeff,

Corrected ur script:

------------------------------
#!/usr/bin/sh

REMOTE=111.222.333.444
USER=user123
PW=password123
DIR=/directory
FILE=*.jef

echo "### Transferring the files from server1 to server2 ###"
ftp -n $REMOTE << EOF
user $USER $PW
cd $DIR
mput $FILE
bye
EOF
------------------------------

Cheers...
Satish
Difference between good and the best is only a little effort
Alan Riggs
Honored Contributor

Re: FTP script not complete

You just need to use command line redirection in your original script (also called a "here document").

ftp << END
open . . .
.
.
.
END

I would suggest using a .netrc file, though, in cases where you are not logging in as "anonymous" or "ftp"
Anthony deRito
Respected Contributor

Re: FTP script not complete

Jeff, ftp is interactive (unlike tftp) and so it requires interactive user commands. A work around is to have you script write all the ftp commands to a temporary file and then use that file as input to ftp. Here is an example...

echo "binary" > /tmp/pos_ftp.$$
echo "put $jcl_file" >> /tmp/pos_ftp.$$
echo "quit" >> /tmp/pos_ftp.$$
ftp $HOST < /tmp/pos_ftp.$$

The .netrc file in the home directory of the user doing the ftp would specify the host and also the authentication information. If your concerned about the security issue then this would not be good for you because the password is plain text.

Do a man on .netrc for more info.

Tony
Sanjay_6
Honored Contributor

Re: FTP script not complete

Hi Jeff,

Use this,

REMOTE=111.222.333 (remote server's IP address)
USER=user123
PW=password123
DIR=/directory
FILE=*.jef

echo "### Transferring the files from server1 to server2 ###"
ftp -n $REMOTE <user $USER $PW
cd $DIR
bin
mput $FILE
EndFTP


Hope this helps.

Regds