Looping through the directory

Hi,
I have to write a KSH script to loop through the directory and transfer all the files through FTP. The source machine is the Network shared drive and the files in the directory needs to be FTPied to the UNIX server.

For eg. Directory (Datasource)
+ Directory1
-file1
-file2
+ Directory2
-file3
-file4
+Directory3
-file5
-file6

How to loop through the above directory structure.

Please help me out.

Thanks
Lakshmi

can anybody help me out on this.

Please read the rules of the forum :slight_smile:

Looping through the directory -- does that mean all the files to be transferred starting from a specific directory ???

If that is the requirement, use find command to list all the files that are to be transferred and build a ftp script for that.

this could be done on the run and no multiple manual intervention would be needed.

With the available list of selected files,
prepare ftp commands like

put file1
put file2

this is just a pointer :slight_smile:

hope this helps :slight_smile:

Perhaps there is something useful in the FAQs?

I had written the script to transfer the files through FTP. So I wanted to know about how to loop through the directory.

Can anybody help me with an example script.

Thanks

MYDIR=/home/sri/kanth
cd $MYDIR
TEMP1=`ls -1 >$MYDIR/temp1`

for i in `cat $TEMP`
do
        echo $i  # file name which resides in $MYDIR directory
        echo " you can do something with files"
        bla bla bla
           -----------
          -----------
          ----------
done

I think this the code you are looking for
if not ...pls post your code, we try to give the solution..

thank
srikanth

Yesterday the scripts which I had got is not working. Can anybody help me out with some examples.