ftp in a for loop


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting ftp in a for loop
# 1  
Old 07-13-2004
Data 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} <<EOF >> ./ftp.log
user $MF_LOGIN $MF_PASSWORD
verbose
status
${COMMAND} ${RS6000_FNAME} \'"${MF_FNAME}"\'
quit
EOF
done
# 2  
Old 07-13-2004
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.
# 3  
Old 07-15-2004
Hello rao,

You should make sure the command lines in the ftp section of the scripts don't start with the space character.
# 4  
Old 07-15-2004
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.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk loop using array:wish to store array values from loop for use outside loop

Here's my code: awk -F '' 'NR==FNR { if (/time/ && $5>10) A=$2" "$3":"$4":"($5-01) else if (/time/ && $5<01) A=$2" "$3":"$4-01":"(59-$5) else if (/time/ && $5<=10) A=$2" "$3":"$4":0"($5-01) else if (/close/) { B=0 n1=n2; ... (2 Replies)
Discussion started by: klane
2 Replies

2. Shell Programming and Scripting

Array Variable being Assigned Values in Loop, But Gone when Loop Completes???

Hello All, Maybe I'm Missing something here but I have NOOO idea what the heck is going on with this....? I have a Variable that contains a PATTERN of what I'm considering "Illegal Characters". So what I'm doing is looping through a string containing some of these "Illegal Characters". Now... (5 Replies)
Discussion started by: mrm5102
5 Replies

3. Shell Programming and Scripting

FTP script loop

Hi, I'm trying to login to 100 boxes using a script. I have a file called 'hosty' which has all the ip addresses. Is there a way I can pass the password to the script then move on to the next box ?Basically I'm trying to test my password on all the boxes. AIX machines.. Here's what I have... (2 Replies)
Discussion started by: Grueben
2 Replies

4. Shell Programming and Scripting

send files through ftp using proxy in a loop

Hi, I have a problem with sending files to ftp using proxy. When using this script: #!/bin/bash DIR=/dane_wz ftp -n -v 172.30.100.13 << EOF quote USER xxx@172.25.240.45 quote PASS xxxx passive cd $DIR quit EOFit works fine and I get connection with FTP server, but using the same in a... (2 Replies)
Discussion started by: vrolok
2 Replies

5. HP-UX

[Solved] Unable to rename file in ftp server .Net:FTP perl

Hello All, I am trying to connect to ftp server and get the files. Also i need to rename the file in other ftp dir. rename method is not allowing me to rename the file in other dir. When i tried copy command by using net::FTP:FILE then perl says it is not installed. Can some body help me to... (2 Replies)
Discussion started by: krsnadasa
2 Replies

6. Shell Programming and Scripting

Need code to ftp files in loop

I have files like this beginning from 082008 (MMYYYY) to 112010 (MMYYYY) I need to fetch this files through ftp in loop. How can I achieve it? I tried with the following code. But I'm not sure how to increment the month from 082008 to 112010. for i in {082008 .. 112010} ... (5 Replies)
Discussion started by: Gangadhar Reddy
5 Replies

7. Shell Programming and Scripting

Automated FTP script using .netrc to multiple FTP servers

Hi all, I'm using the following script to automated ftp files to 1 ftp servers host=192.168.0.1 /usr/bin/ftp -vi >> $bkplog 2>&1 <<ftp open $host bin cd ${directory} put $files quit ftp and the .netrc file contain machine 192.168.0.1 login abc... (4 Replies)
Discussion started by: varu0612
4 Replies

8. Shell Programming and Scripting

ftp transfer in a for loop

Frdz, i have scenorio like i have to open ftp connection in a for loop and connect to the other server and upload the file again and again till the for loop ends but i am getting problem when i use the following code. for i in `ls ${SOURCE_DIR}/` do FOLDER_NAME=`basename $i` for j in `ls... (4 Replies)
Discussion started by: KiranKumarKarre
4 Replies

9. Shell Programming and Scripting

FTP and run a loop for array problem

Hello, I have a problem with my script whereby it does not want to loop. The function of my script is to FTP into a server and go to each directory/volume in the array 'VOL'. The way the loop is suppose to work, is to go into the first volume, get the files of R(yesterday's date) and... (3 Replies)
Discussion started by: tuffgong2008
3 Replies

10. UNIX for Advanced & Expert Users

Using FTP to check whether file is completely FTP... plz find the description below

Hi, We have some clients who will place huge files in to one of the remote server. And the shell script written in our local server to retrieve client files (using FTP) placed on one of the remote server of ours by clients. My question Is there any FTP command/script to check from my local... (1 Reply)
Discussion started by: nmsrao
1 Replies
Login or Register to Ask a Question