Scripted FTP transfer
- From: "Julian Brett" <nospam@xxxxxxxxxxxxxx>
- Date: Tue, 22 Apr 2008 10:34:21 +0100
Hi all.
I'm attempting to script an FTP transfer on my UnixWare 7.1.4 server. I've
written numerous FTP transfer scripts before, but haven't really approached
it this way.
What I'd like to do is basically retrieve some files from a remote system,
then move them at the remote end into an archive folder. Sounds pretty
simple.
In my script, I'm trying to write a FTP command file on the fly to redirect
into my FTP command as follows:-
===========
:
ftphost=ftp.XXXXXX.com
ftpuser=XXXXXX
ftppass=XXXXXX
ftpdir="/"
ftparcdir="/arcdir"
work=/tmp/xfer.$$
#
# get list of files waiting
ftp -g -n ${ftphost} > ${work} 2>&1 << !
user ${ftpuser} ${ftppass}
cd ${ftpdir}
dir
bye
!
# process file list into ftp commands
exec 3< ${work}
while read line <&3
do
filename=`echo ${line} | awk '{print $4}'`
fileext=`echo ${filename} | awk -F\. '{print $2}' | dd conv=ucase
2>/dev/null`
if [ "${fileext}" = "XML" ]
then
echo "get ${filename}" >> ${work}.2
echo "ren ${filename} ${ftparcdir}/${filename}" >> ${work}.3
fi
done
# write ftp script file to retrieve all XML files
#echo "OPEN ${ftphost}" > /tmp/ftp.$$
echo "USER ${ftpuser} ${ftppass}" >> /tmp/ftp.$$
echo "binary" >> /tmp/ftp.$$
echo "cd ${ftpdir}" >> /tmp/ftp.$$
cat ${work}.2 >> /tmp/ftp.$$
cat ${work}.3 >> /tmp/ftp.$$
echo "bye" >> /tmp/ftp.$$
# run script to transfer all XML files and archive them
ftp -i -g -n ${ftphost} < /tmp/ftp.$$ > /tmp/ftp$$.log 2>&1
rm -f ${work} ${work}.2 ${work}.3
cat /tmp/ftp$$.log
rm -f /tmp/ftp$$.log
rm -f /tmp/ftp.$$
exit 0
===========
The script runs and creates my command file, but I just cannot get it to
accept the commands from the temporary file. I have removed the redirect to
the ftp$$.log file, and stripped out the relevant commands and run them
directly from the command line.
The output I get (either on the screen, or in the ftp$$.log file) is:-
?Invalid command
?Invalid command
Not connected.
Not connected.
Not connected.
Not connected.
Not connected.
Not connected.
This is the method for ftp which I have found on Google, but cannot
understand why it isn't working on my Unixware system. I get exactly the
same results on an Openserver 5.0.6 system too.
Any ideas what I'm doing wrong here?
I suppose I could also do a "mget *.xml" in this instance, but not knowing
the case of the files (it could be another Unix or Linux system at the other
end - I don't know), this may not work.
Many thanks,
Julian.
.
- Follow-Ups:
- Re: Scripted FTP transfer
- From: bcohen
- Re: Scripted FTP transfer
- From: David Font
- Re: Scripted FTP transfer
- From: Tony Lawrence
- Re: Scripted FTP transfer
- From: ThreeStar
- Re: Scripted FTP transfer
- Prev by Date: Re: No memory for streams (NSTRPAGES)
- Next by Date: Re: Scripted FTP transfer
- Previous by thread: Alleged discrimination and failure to pay for vacation and holiday time at SCO
- Next by thread: Re: Scripted FTP transfer
- Index(es):
Relevant Pages
|