Parse the .txt file for folder name and FTP to the corrsponding folder.

Oracle procedure create files on UNIX folder on a regular basis. I need to FTP files onto windows server and place the files, based on their name, in the corresponding folders. File name is as follows: ccyymmddfoldernamefile.txt; Folder Name length could be of any size; however, the prefix and suffix are of a fixed size.

e.g:
1) 20070701greenfieldincfile.txt (Folder Name: greenfieldinc)
2) 20070701oldenergycorpfile.txt (Folder Name: oldenergycorp)

Detailed Request:
1) Parse the Input File name and Find the name of the folder.
2) FTP to Windows server and place the text file in the corresponding folder.
3) Put the whole process in loop until it processes all files.
4) If possible any error check conditions or logs.

Thank you for your support!

#!/usr/bin/ksh
ls -1 file.txt | while read FILENAME
do
DIRNAME=`echo "$FILENAME" | sed -n 's/........\(.
\)file.txt/\1/p'`
echo "starting FTP of $FILENAME to Directory /tmp/$DIRNAME ..."
ftp -v -n host <<EOF
user user pwd
cd /tmp/$DIRNAME #destination Dir
lcd /tmp/source/ #source dir
put "$FILENAME"
bye
EOF
done

The provided script did work. Thank You so much!

However, the created file hasn't been granted 'write' privileges to the user. The file is getting created through Oracle trigger and the process automatically uses 'dbadmin' user on UNIX.

Is there any way that we can force UNIX to provide 'r' & 'w' privileges to group and other members for the files that get generated through that process or files that get generated in the specified directory.

Any help is greatly appreciated.

Thanks!

To set subsequently created files to a specific privileges:

man umask