Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

KSH script to FTP

Status
Not open for further replies.

ryanc2

MIS
Apr 18, 2003
73
US
Trying to run a while loop to search directories loaded in control file and ftp new files. Runs fine without ftp commands, but get syntax error `<<' unmatched when included. Please Help?!?

#--------------------------------------------------------
# Function: FTP - Move files to WMS system
#--------------------------------------------------------
ftp_exp () {
IFS=:
exec 6< ${WMSDATA}/exp_mvr.cntl
while read -u6 type file l_dir r_ip id pw r_dir
do
# - Build Archive and FTP
cd ${l_dir}
if [ -s ${file}_prep.tmp ]; then
log &quot;## Preparing ${file} Archive&quot;
(tar cvf ${file}_ftp.tar `cat ${file}_prep.tmp`) 2> ERR_${file}
compress -f ${file}_ftp.tar

# - FTP Archive to WMS
ftp ${ftp_args} ${ip} <<EOF
user ${id} ${pw}
binary
cd ${r_dir}
put ${file}_ftp.tar.Z
quit
EOF
fi
done
}
 
You have a 'misaligned' EOF

tried using the 'here-document' with a '-'?
like so

ftp whatever <<-EOF
a
b
c
EOF

from 'man ksh':

<< [-]word
The shell input is read up to a line that is the
same as word, or to an EOF. No parameter substi-
tution, command substitution or file name genera-
tion is performed on word. The resulting document,
called a here-document, becomes the standard
input. If any character of word is quoted, then
no interpretation is placed upon the characters of
the document; otherwise, parameter and command
substitution occur, \NEWLINE is ignored, and must be used to quote the characters \, $, `, and
the first character of word. If - is appended to
<<, then all leading tabs are stripped from word
and from the document.


vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
vgersh99,

Thanks for the response. I changed to reflect as follows:

ftp ${ftp_args} ${ip}<<-EOF
user ${id} ${pw}
binary
cd ${r_dir}
put ${file}_ftp.tar.Z
quit
EOF

I still get the same syntax error as before: `<<' unmatched. Any other help would be greatly appreciated.
 
the following works fine on Solaris - make sure you have 'tabs' inside the 'here-doc':

ftp -n hostName <<-EOF
user user password
ls /tmp
quit
EOF


vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
Might I also suggest you switch to RCP or SCP instead of FTP. The format is very easy and it eliminates the EOF issue that seems to plague people.

RCP/SCP also has the advantage of being able to more easily validate success, report errors and continue processing. For example you may wish to send all 50 files from a directory to another site. File 31 does not make it, you send an alert, try again, etc., but keep going. Possible with FTP? Certainly, but another tool in the box may be easier to use. scp has the additional advantage that once you setup the keys, passwords are not within the scripts and the transfer is encrypted.

 
Thanks for the input:

vgersh - thanks for the help, my tabs were off like you said. However, during the while loop, the script does not recognize each file for a seperate sequence of events.

For example:

#!/bin/ksh
IFS=:
exec 6< control file
while read -u6 type file l_dir r_ip id pw r_dir
do
ls WA* > $file_prep.tmp
if [ -s file_prep.tmp ]; then
for f in `cat file_prep.tmp`
do
ftp $ftp_args $r_ip <<-EOF
user $id $pw
binary
prompt
put $f
quit
EOF
done
fi
done
#

What happens is the first file in the list $file_prep.tmp is passed correctly, but each subsequent filename is passed instead of a seperate ftp sequence for each.

Result:

ftp -ni ip_address
user id pw
binary
put filename1
fileneame2
filename3
quit

What I want:

ftp -ni ip_address
user id pw
binary
put filename1
put filename2
put filename3
quit

gamerland: I am doing this from UNIX to NT with between 2k-3k files per day (no more than 200 at a time). Can this be accomplished with rcp?

Thanks again in advance for any help...you guys are great.
 
not quite sure what's going on here, but.......

shouldn't it be like that?

#!/bin/ksh

exec 6< control file
while IFS=':' read -u6 type file l_dir r_ip id pw r_dir
do
ls WA* > ${file}_prep.tmp
if [ -s ${file}_prep.tmp ]; then
for f in `cat ${file}_prep.tmp`
do
ftp $ftp_args $r_ip <<-EOF
user $id $pw
binary
prompt
put $f
quit
EOF
done
fi
done

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
vgersh -

Will your changes fix my problem, or is it just correcting a syntax error?

1). Read a control file for different file types

type1:local_directory:remote_directory:ip:user:pw
type2:local_directory:remote_dircetory:ip:user:pw
type3:local_directory:remote_directory:ip:user:pw

2). Loop through control file and list each file type to temp file

3). For each file type, ftp all files found in local_directory

Everything has been working fine, except for the ftp part.

For example. For file type type1, the script finds three new files to FTP. They are listed into a tmp file (ls files* > type1_prep.tmp. If you viewed that list it would show

file1
file2
file3

The ftp acts as follows

ftp -ni ip
user id pw
binary
put file1
file2
file3
quit

How do I read the list of 3 files so it does either an mput for all files or a seperate put for each file in the list.

Sorry for being so long winded.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top