ftp in a for loop

All,
ll,
I am trying to ftp multiple files. I borrowed the ftp logic from existing script.
When I enclose the ftp in a for loop, I get a syntax error "'<' unmatched"
I checked all the variables I am using ...
please help...
TIA
Rao

files=$\(ls $\{LI\_REPORT\_FILE_PRE\} \)
for file in $files
do 
         \# the error point to following line
         \# If I execute following 7 lines outside for loop it works
         ftp -n -i  $\{MF_NAME\} $\{FTP_PORT\} &lt;&lt;EOF &gt;&gt; ./ftp.log 
         user $MF_LOGIN $MF_PASSWORD
         verbose
         status
         $\{COMMAND\}  $\{RS6000_FNAME\}  \\'"$\{MF_FNAME\}"\\' 
         quit  
         EOF
    done

Your technique is going to fire up a separate ftp process for every file (if you get it working). That is not very efficient.

Please navigate
Our Home Page -> Answers to Frequently Asked Questions -> Automate FTP / Scripting FTP Transfers

to see another way to do it.

Hello rao,

You should make sure the command lines in the ftp section of the scripts don't start with the space character.

Hi,
Not sure if this is what your looking for, but I've had the situation where I've had to get many files but have been unable to use mget (not supported on remote host).

Rather than looping an ftp each time for each file, I made a script that would build a single script file to do the mutilpe gets.

In this example I had to get files that had a four digit sequence, you change file name generation to what you need.

Usage, script_name <output file> <node IP> <userid> <passwd> <start seq.> <end seq.>

The output file should have all the files to collect from one ftp connection.

print "#!/usr/bin/ksh" > $1
print "ftp -n $2 << -EOF" >> $1
print " user $3 $4" >> $1
print " binary" >> $1
i=$5
while [ "$i" -le $6 ]
do
name=`echo ${i} | awk '{printf "CF%04d.DAT\n", $1}'`
print " get $name" >> $1
i=`expr $i + 1`
done
print " bye" >> $1
print "EOF" >> $1
print "echo DONE" >> $1

Hope this off some help. I'm sure (though haven't looked) the FAQ has some other good ides.