Loops within ftp shell session

Hi guys,
i need to script the sending of multiple files through one ftp session. I have done this so far:
----------------------------------------------------------------
#!/bin/sh
USER=myuser
PASSWD=mypass
filenum=$1
x=0

ftp -n 159.167.95.199 <<SCRIPT
user $USER $PASSWD
binary
while [ $x -lt $filenum ]
do
cd pacsftp01
put test.txt
delete test.txt
x=`expr $x + 1`
done
quit
echo $x files transferred
SCRIPT
--------------------------------------------------------------------
questions:
How can i execute a while loop within the ftp sessions?
What does "<<SCRIPT" do?

Thnks,
Zaff

zaff,
You are trying to loop inside the ftp command (everything that you are doing after the << is inside the ftp command) That is not going to work, as ftp does not support these commands.

A better suggestion is to construct a ftp script and feed it to the ftp program.

#!/bin/sh
USER=myuser
PASSWD=mypass
filenum=$1
x=0

echo "open 159.167.95.199
user $USER $PASSWD
binary
cd pacsftp01" > /tmp/ftp.$$
while [ $x -lt $filenum ]
do
echo "put test.txt
delete test.txt" >> tmp/ftp.$$
x=`expr $x + 1`
done
echo "quit" >> /tmp/ftp.$$
ftp -ivn < /tmp/ftp.$$
echo $x files transferred
rm /tmp/ftp.$$

thanks for that Blowtorch!

My only comment is that the entire time you are transferring the ftp files, your USER and PASS are world-readable in /tmp/ftp.$$

My only comment is that lots of folks seem to be ignoring the faq section. *sigh* But, oh well, at least some people read them.