Scripted FTP transfer



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.


.



Relevant Pages

  • Re: Run scripts from WITHIN the FTP environment
    ... Go look up how to do scripting with a batch file in FTP. ... If you think the FTP command can be brainless and NOT have a file on the ... There is no way to "push" a script to the computer without having the user ... to execute a script in the directory they are in. ...
    (microsoft.public.inetserver.iis.ftp)
  • Re: Scripted FTP transfer
    ... Rather then specify the username and password in your script, ... going to run the ftp script, ... If you are running this from root, the .netrc will be created in / ... I'm trying to write a FTP command file on the fly to ...
    (comp.unix.sco.misc)
  • Re: Scripted FTP transfer
    ... I'm attempting to script an FTP transfer on my UnixWare 7.1.4 server. ... I'm trying to write a FTP command file on the fly to redirect ...
    (comp.unix.sco.misc)
  • Re: Run scripts from WITHIN the FTP environment
    ... Your script I assume uses the Windows command line based FTP program? ... to execute a script in the directory they are in. ...
    (microsoft.public.inetserver.iis.ftp)
  • Re: FTP PUT with Store Unique
    ... years ago but had totally forgotten - I appreciated that the STOU command is ... covers the point I want to make which is that the FTP client commands are ... An SUNIQUE command compatible ...
    (bit.listserv.ibm-main)