Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

automating ftp session

Status
Not open for further replies.

dwcasey

MIS
Oct 31, 2002
179
US
I've got the following script that is not working. Trying to automate an ftp session. I've got a simple ls command in there to just see if I can get connected and do a file listing.

#!/bin/ksh -x

HOST='server01.domain.com'
USER='joe'
PASSWD='letmein'

ftp -inv $HOST << "EOF"
user $USER
$PASSWD
ls
bye
EOF

I fails at the user/pass. I've tried

user $USER $PASSWD

user $USER
pass $PASSWD

If I do it by hand, I get:

server22:/usr/local/bin # ftp server01
Connected to server01.domain.com.
220 server01 FTP server (Version 4.1 Tue May 15 16:38:46 CDT 2001) ready.
Name (server01:root): joe
331 Password required for joe.
Password: xxxxx
230 User joe logged in.
ftp> bye
221 Goodbye.
 
That's good if I'm hitting another AIX box, but what if I want to drop these files on an Windows box?
 
.netrc is good, i prefer ssh
your probl is the newline between
$user and $passwd
try:

ftp -inv $HOST << EOF
user $USER $PASSWD
ls
bye
EOF
 
You may also want to look into Expect which is available for AIX. It is a scripting language that allows examination of responses and altered logic based on results. We do all our ftp I/O with this and it works very well under varying conditions and situations.


Bob
 
try using a perl script :

We connect to the Mcafee ftp for updates for our Av, every 30 min through a proxy server.

here's a snippet of the code

$ftp=Net::FTP->new("IPadress of proxyserver",Debug => 1)|| die "$@ can't connect\n";
$ftp->login('anonymous@ftp.nai.com','user@mail.com');
print "Connection succeeded";
$ftp->cwd("/pub/antivirus/datfiles/4.x");
$ftp->binary();
@dirlist = $ftp->ls();
and so on...

greetz,

R.
 
I 'va got this problem trying to ftp to a windows server.
Doing as below solve it for me.

echo "user domain/username password" >> FILE
echo "ftp commands" >> FILE
echo "quit" >> FILE
ftp -vgin hostname < FILE
rm FILE


Bye
 
You cannot use the here-document like <”EOF” and end it like <EOF ; it would have to end <”EOF”

The best way to do it is <-EOF and end it <-EOF ---- note the (-)

Also enclose your ftp in parentheses () and tab your lines between the first and last lines.
 
For example:

#!/bin/ksh

for i in $(cat /tmp/solarishosts)
do
(
ftp -i -n -v $i <<-EOF
user USER PASSWORD
bin
cd /export/home/USER
put metacheck
bye
EOF
)
done
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top