Operating System - HP-UX
1832864 Members
2812 Online
110048 Solutions
New Discussion

I lost this one: FTP ISSUES

 
Richard_115
Frequent Advisor

I lost this one: FTP ISSUES

I am having a problem ftp(ing) into a system. The first time, I use a function which goes into all ( 50 ) systems and collects data. That works fine. The second time, I invoke another ftp function from within another function but in this new ftp function I dont use a loop. Either way, I get an error on <
function one_system
{
HOST="$record"
for j in "$HOST"
do
echo $j
cd $FTPDIR/$j
ftp -n -i -v $j < user XXXX YYYY
bin
cd $RUNLOGDIR
get run.log
bye
END
done
}

Does anybody see any error?
If I remove the <
6 REPLIES 6
Graham Cameron_1
Honored Contributor

Re: I lost this one: FTP ISSUES

Looks ok but maybe characters got lost between the cut and paste.

Does your closing END begin on col 1, or is it indented?

If there is whitespace before it, then you need to use <<- instead of <<
on your ftp line.

-- Graham
Computers make it easier to do a lot of things, but most of the things they make it easier to do don't need to be done.
Stefan Farrelly
Honored Contributor

Re: I lost this one: FTP ISSUES

I think its because when you call the function "one_system" standard input is coming from the line where you call it, which negates the standard input of the <
one_system <&-
or
one_system <&p

see man sh_posix under section on Input/Output
Im from Palmerston North, New Zealand, but somehow ended up in London...
Richard_115
Frequent Advisor

Re: I lost this one: FTP ISSUES

Stefan

Thanks for that pointer. However, the line user XXX YYYY does not execute. Any reason ?
Rusty Sapper
Frequent Advisor

Re: I lost this one: FTP ISSUES

I would just forget ftp all together. You have a couple security risks in having the username and password in a readable script as well as transmitting the password in plain text.
You can accomplish the same thing very simply using scp (secure copy)


-Rusty
Stefan Farrelly
Honored Contributor

Re: I lost this one: FTP ISSUES

Ive tried calling ftp <
cd $RUNLOGDIR
to
cd \$RUNLOGDIR

and see if that works.
Im from Palmerston North, New Zealand, but somehow ended up in London...
David Andrews_1
Advisor

Re: I lost this one: FTP ISSUES

I would build an FTP script for each using a .netrc file

Eg.

for J in "$HOST"
do
echo $J
cd ${FTPDIR}/$J
if [ -f ~/.netrc ]
then
mv ~/.netrc ~/.netrc.old
fi
echo "machine $J" > ~/.netrc
echo "login XXXXX" >> ~/.netrc
echo "password YYYYY" >> ~/.netrc
echo "macdef init" >> ~/.netrc
echo "binary" >> ~/.netrc
echo "cd $RUNLOGDIR" >> ~/.netrc
echo "get run.log" >> ~/.netrc
echo "bye" >> ~/.netrc

chmod 700 ~/.netrc
ftp -i $J
mv ~/.netrc ~/.netrc.$J
done

Then sit back and relax.

Important stage is chmod 700!!!