For looping on FTP


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users For looping on FTP
# 1  
Old 01-25-2012
For looping on FTP

Hi,

I have a requirement, where i have to check multiple folders(number of folder may vary) for a file and fetch the file one at a time and load it.

On the ftp part, I fetch the file, Copy it to Archive folder and then remove the original file

Code:
for flist in $folder_list; do 
   print -p cd  $flist
   print -p ls -lrt
   CFNAME=DELREAD.DAT
         print -p get $CFNAME ${DATA_PATH}/${CFNAME}_${flist}_${DATESTAMP}
print -p cd ..
   print -p cd Archive  
    print -p put ${DATA_PATH}/${CFNAME}_${flist}_${DATESTAMP} ${CFNAME}_${flist}_${DATESTAMP}
   print -p cd ..
   print -p cd $flist
   print -p ls -lrt
   print -p del $CFNAME
done

The above script will look into all the folders and fetch all the files, copy them to Archive and remove them.. but I would like to include a check. Whenever it finds the first file... come out of the loop. Is there a way to do a return code check after the get command?

Last edited by methyl; 01-25-2012 at 01:47 PM.. Reason: please use code tags
# 2  
Old 01-25-2012
What do you mean, "finds the first file"?
# 3  
Old 01-25-2012
Say if there are total 10 folders.. of them 4 folders(fold2, fold5, fold7 and fold8) have DELREAD.DAT file. Once it find the file from fold2. I should come out of that loop. and next time when the script is executed.. it should come out at fold5
# 4  
Old 01-25-2012
The script as posted outputs a mixed variety of Shell and ftp commands to the screen (using the "print" command) but without executing them. Also, many of the variables referred to in the script are never set with a value.
Have you posted the correct script?
# 5  
Old 01-25-2012
The whole script does few other stuffs. I have copied the section where i have this question.

Code:
for flist in 1 2 3 4 5 6 7 8 9; do 
   print -p cd  $flist
   print -p ls -lrt
   CFNAME=DELREAD.DAT
         print -p get $CFNAME /tmp/${CFNAME}_${flist}_${DATESTAMP}
print -p cd ..
   print -p cd Archive  
    print -p put /tmp/${CFNAME}_${flist}_${DATESTAMP} ${CFNAME}_${flist}_${DATESTAMP}
   print -p cd ..
   print -p cd $flist
   print -p ls -lrt
   print -p del $CFNAME
done

I have changed those variables with fixed value for clear understanding.

Last edited by methyl; 01-25-2012 at 08:54 PM.. Reason: please use code tags
# 6  
Old 01-25-2012
It is impossible to determine what the script writer intended from this code.

To be quite blunt the script as posted does nothing except output strings to the screen using "print" statements. None of the command lines (except the "for") do anything useful. The "put" command is a "ftp" command but the script does not run the "ftp" program or even mention another server (e.g. the server to receive the data files).

Please post sample input and sample output, and a brief but well-written description of the process which turns sample input into sample output?

When working with files which have the same name, consider where we are transfer such files and what to do if there is already a file with the same name on the target server. Do we need to re-create the same directory tree on the target server?

Last edited by methyl; 01-29-2012 at 06:34 PM..
# 7  
Old 01-26-2012
It sounds to me like he wants to insert a conditional statement into the for loop to stop after a successful event?

perhaps using
Code:
 if [ $? -eq 0 ]; then break;fi

something along those lines?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Looping

Hey guys, so I am trying to do a loop script that will go through each folder (no gui so just each domain has a folder) and grab out the databases being used on that domain. I know I would use mysql -e "show databases where not 'information_schema';" once in each directory to pull the actual... (3 Replies)
Discussion started by: dough
3 Replies

2. Shell Programming and Scripting

Odd looping issue with NET::FTP and Proftpd

Hello, I'm a UNIX SysAdmin at a large webhosting company and we have a vendor that provides a service which involves the ftp'ing of files from their servers to ours. They initiate FTP using a perl script with NET::FTP. When they try to transfer files (and delete files over ftp), there is... (3 Replies)
Discussion started by: tmmgeekette
3 Replies

3. Shell Programming and Scripting

Looping

Hi evryone i need a help . i have a file xcv.the content is : accelerate i want a script which will run 1000 times in loop and changing the value to accelerate to acceler in 1st loop and in 2nd loop it will be again accelerate and so on . (6 Replies)
Discussion started by: Aditya.Gurgaon
6 Replies

4. Shell Programming and Scripting

Looping in FTP session

Hi I am trying rename multiple files in a remote location by connecting through FTP. How do i do this? I get error as for is not FTP command. I looked the FAQ for scripting but it is doesnt relate to my post. Please help. Thanks ftp -in >Error.log <<! open $HOST user $User $Pwd for... (2 Replies)
Discussion started by: appsguy616
2 Replies

5. Shell Programming and Scripting

Looping

Hi, Now I have written a script which sorts the records in the file and splits them according to some condition. Now, I need to modify the script so that it reads all the files one after the other and does the sorting & splitting. Pls help me in reading all the files in a directory and... (8 Replies)
Discussion started by: Sunitha_edi82
8 Replies

6. Shell Programming and Scripting

help with looping

vesselNames values: xxx yyy zzz vesselPlanned values: xxx zzz zzz zzz OIFS="" OIFS=$IFS IFS="\n" (2 Replies)
Discussion started by: finalight
2 Replies

7. Shell Programming and Scripting

help on looping using if/for or while

Hello, where can I get usefull information on the use of looping with for , if and while with extensive examples. Also use of variables in scripts (1 Reply)
Discussion started by: sam4now
1 Replies

8. Shell Programming and Scripting

for looping

I run into a issue when I try to do sorting of the following with ascending order, one round of for looping seems not working, anyone knows how to use shell or perl? $array = (5,0,3,2,7,9,8) (2 Replies)
Discussion started by: ccp
2 Replies

9. Shell Programming and Scripting

looping

Hi I have around 100 users in sun server and have default home directory in /usr/home/<username> I want to clean their home directory time to time to make free space on root, as users generate many output files during usage of application. My idea is, generate a file with following command... (4 Replies)
Discussion started by: ishir
4 Replies

10. UNIX for Dummies Questions & Answers

Help with looping

Hi, Actually I have a file which consists data . for eg names. Then I want my sql query to read this file and produce the output. Currently I am using this FOR EG : FILENAME is NAMES for i in `cat NAMES` { sqlplus -s $CONNECTID << EOF spool rooh set heading off select... (1 Reply)
Discussion started by: rooh
1 Replies
Login or Register to Ask a Question