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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ftp error at '<<' 1

Status
Not open for further replies.

jazie

Programmer
Jun 17, 2004
5
0
0
US
Hi,
I have a shell that spp to ftp to a host and get several files based on the filenames passed on command line.

For example: ksh script.sh file1 file2.txt file3.xls

for arg in "$@"
do
FILE=$arg
ftp -n -i -v <<SCRIPT
open $HOST
user $USER $PASSWD
cd $HOSTDIR
bin
get $FILE$DT$EXT
quit
SCRIPT
done

This works when the ftp code segment is ran outside of the loop, but when I have it within a loop like above, there is a syntax error at '<<' I don't understand why. Can someone please advise.

thanks.
 
Have you tried this ?
for arg in "$@"
do
FILE=$arg
echo "\
open $HOST
user $USER $PASSWD
cd $HOSTDIR
bin
get $FILE$DT$EXT
quit
" | ftp -n -i -v
done

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
The tag marking the end of your "here document" cannot have any spaces in front of it.
 
ericbrunson said:
The tag marking the end of your "here document" cannot have any spaces in front of it.
... unless you put a dash '-' just after the '<<'.

In this case all TABs (and only TABs) are stripped from the start of the following lines before they are used (either for checking against the 'EndOfHereDocument' string or as input for your command)
Code:
for arg in "$@"
do
  ftp -n -i -v <<[COLOR=blue][b]-[/b][/color]SCRIPT
	open $HOST
	user $USER $PASSWD
	cd $HOSTDIR
	bin
	get $FILE$DT$EXT
	quit
	SCRIPT
done
Note that the "space" at start of lines are true TABs characters.

--------------------

Denis
 
Thanks everyone.

I tried dchoulette's code before the post, but it still had the same error.

I tried the Piping that PHV suggested and this works.

Thank you.
 
This is how I do it:
Code:
for i in $(cat /export/home/user/hosts)
do
        (
        ftp -i -n -v $i <<-EOF
        user NAME PASSWORD
        bin
        cd /export/home/user
        get $FILE$DT$EXT
        bye
        EOF
        )
done
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top