home *** CD-ROM | disk | FTP | other *** search
- /*
- * Ax ARexx-FTP interface script
- * FTP client: ncFTP
- * $VER: FTP_ncFTP.ax 1.0 (6.12.96)
- *
- * Version 1.0
- * by Paul A. Schifferer
- * Copyright 1996 © Isengard Developments
- *
- * This script is freely distributable and modifiable. You are authorized to
- * modify it to suit your needs. Isengard Developments makes no warranty,
- * express or implied, for its usability or reliability in its original or
- * modified form.
- *
- * This script takes an optional list of files to retrieve with the FTP client
- * program noted above. If 'files' aren't specified on the command line, the
- * script will attempt to interface with Ax, using the ARexx port name "AXFTP"
- * to get files. Alternatively, 'files' can be "LIST=filename", which
- * specifies the list of files to use (see below). If files are specified on
- * the command line for this script, then the first parameter must be the site
- * name, the second the base directory, and all subsequent parameters are
- * files in the form of 'path/filename' (relative to the base path).
- *
- * The file list is in the following format:
- *
- * The first line is the site from which to retrieve the files. The second
- * line is the base directory to use, e.g., '/pub/aminet', without the
- * trailing slash. This dir should always be an absolute path, i.e., with
- * the beginning slash.
- *
- * All subsequent lines are files to retrieve in the form of 'path/filename',
- * e.g., "biz/dbase/Ax.lha". 'path' need not be specified, if the file is
- * located in the base directory. Note that all paths should be specified
- * relative to the base directory, but this is not a requirement. Absolute
- * pathnames may be used.
- *
- * A line with three hashes ('###') ends the filelist. Everything thereafter
- * is ignored.
- */
-
- options results
- signal on syntax
- signal on error
-
- parse arg files
-
- /*
- * Is Ax running?
- */
- if (length(files) = 0) & ~show('P',"AX") then do
- say "Ax must be running to use this script!"
- exit 20
- end
-
- /*
- * Set up some variables.
- */
- clientname = "ncFTP"
- scriptname = "FTP_"clientname".ax"
- cmdfile = "T:"clientname"_"pragma('I')
- clientpath = "AmiTCP:bin/ncFTP"
- clientopts = "<"cmdfile
- clientport = ""
- ftpport = ""
-
- /*
- * Command variables.
- *
- * The following variables are commands that would be issued to the FTP client
- * program. The construct is simple: "command parameter options". Place
- * the client's command portion in the variable <a-cmd>cmd, where <a-cmd> is
- * the type of command. This script will place after the command any parameters
- * that are necessary. If the command has options to be specified, place them
- * in the variable <a-cmd>opts. These will be placed at the end of the command,
- * after the parameters.
- *
- * For example, the "GET" command for DaFTP allows you to specify the transfer
- * mode. To set up this command, you would put "GET" in the variable 'getcmd',
- * and "BINARY" in the variable 'getopts'. When the command is issued, it
- * will be sent to DaFTP as "GET <filename> BINARY".
- *
- * It's really very simple. If you are having problems with it, just send me
- * e-mail <gandalf@hughes.net>, and we'll work it out, okay?
- */
- sitecmd = "open -a"
- siteopts = ""
- connectcmd = ""
- connectopts = ""
- portcmd = ""
- portopts = ""
- binarycmd = "binary"
- binaryopts = ""
- cdcmd = "cd"
- cdopts = ""
- lcdcmd = "lcd"
- lcdopts = ""
- getcmd = "get"
- getopts = ""
- quitcmd = "quit"
- quitopts = ""
-
- /*
- * Check if environment var for FTPCLIENT is set and use it. The first line
- * in the var would be the full path of the FTP client to use. The second
- * line, which is optional, specifies any options to use on the command line
- * when starting the client program.
- */
- if exists("ENV:FTPCLIENT") then do
- if open('fc',"ENV:FTPCLIENT",'R') then do
- line = strip(readln('fc'))
- if length(line) > 0 then clientpath = line
- line = strip(readln('fc'))
- if length(line) > 0 then clientopts = line
- end
- call close('fc')
- end
-
- /*
- * Tell Ax to start FTP thread, if not running.
- */
- address AX
- "StartFTP"
- if result = "0" then do
- say scriptname": Unable to start Ax's FTP thread!"
- exit 10
- end
- call time('R')
- do forever
- if show('P',"AXFTP") then leave
- call Delay(250)
- if time('E') > 120 then do
- say scriptname": Timeout waiting for port 'AXFTP'!"
- exit 10
- end
- end
-
- /*
- * Get site name & base dir.
- */
- address AXFTP
- "Site"
- site = result
- "BaseDir"
- basedir = result
- "DownloadDir"
- dldir = result
-
- /*
- * Reset file list.
- */
- "ResetFileList"
-
- /*
- * Main file retrieval loop.
- */
- do forever
-
- /*
- * Open the command file.
- */
- if ~open('cf',cmdfile,'W') then do
- say scriptname": Unable to open command file '"cmdfile"' for writing!"
- address AX "ErrorReq" scriptname": Unable to open command file '"cmdfile"' for writing!"
- address AXFTP "Status" scriptname": Unable to open command file '"cmdfile"' for writing!"
- exit 10
- end
-
- /*
- * Set up port #.
- */
- if length(ftpport) > 0 then do
- call writeln('cf',portcmd ftpport portopts)
- end
-
- /*
- * Connect to site.
- */
- call writeln('cf',sitecmd site siteopts)
-
- /*
- * Set transfer mode.
- */
- if length(binarycmd) > 0 then do
- call writeln('cf',binarycmd binaryopts)
- end
-
- /*
- * Set local directory for downloads.
- */
- if length(lcdcmd) > 0 then do
- call writeln('cf',lcdcmd dldir lcdopts)
- end
-
- /*
- * Were files or a filelist specified?
- */
- filelist = ""
- if length(files) > 0 then do
- if upper(substr(files,1,5)) = "LIST=" then do
- filelist = word(substr(files,6),1)
- c = usefilelist(filelist)
- if c ~= 0 then exit c
- signal doit
- end
- else do
- c = usefiles(files)
- if c ~= 0 then exit c
- signal doit
- end
- end
-
- /*
- * Grab the next file.
- */
- "GetFilename"
- file = result
- if file = "" then leave
- "GetPath ABSOLUTE"
- path = result
-
- if path ~= lastpath then do
- call writeln('cf',cdcmd path cdopts)
- lastpath = path
- end
- call writeln('cf',getcmd file getopts)
-
- /*
- * Tell FTP client to shut down.
- */
- if length(quitcmd) > 0 then do
- call writeln('cf',quitcmd quitopts)
- end
-
- /*
- * Close the command file.
- */
- call close('cf')
-
- /*
- * Start FTP client.
- */
- "Status Retrieving '"file"'..."
- address command clientpath clientopts
-
- /*
- * Set the downloaded flag on the file and remove
- * it from the queue.
- */
- address AXFTP
- "SetFile DOWNLOADED"
- if rc = 5 then address AX "ErrorReq Unabled to update file ('"file"') in database."
- "RemoveFile"
- "NextFile"
- end
-
- /*
- * This section is only for retrieving file specified via file list
- * or on the command line.
- */
- doit:
-
- /*
- * Tell FTP client to shut down.
- */
- if length(quitcmd) > 0 then do
- call writeln('cf',quitcmd quitopts)
- end
-
- call close('cf')
-
- /*
- * Start FTP client.
- *
- * This one is different in that the command-file (i.e., all cd's and file
- * retrieval commands) must be set up BEFORE the client is started. This way
- * the entire command script is passed to the client to essentially automate
- * the process.
- */
- address command clientpath clientopts
-
- /*
- * Tell the user that we're done.
- */
- address AX "ErrorReq ncFTP has completed the transfer."
-
- /*
- * Delete the temporary command file.
- */
- address command "Delete >NIL: "cmdfile "QUIET"
-
- exit 0
-
- /*
- * This procedure lets the script grab files via the FTP client using a file
- * list.
- */
- usefilelist:
- parse arg flist
-
- error = 0
-
- if open('fl',flist,'R') then do
- site = strip(readln('fl'))
- basedir = strip(readln('fl'))
- do while ~eof('fl')
- fpath = readln('fl')
- if fpath = "###" then leave
- if substr(fpath,1,1) = "/" then do /* absolute pathname */
- fpath = reverse(fpath)
- parse fpath fname "/" fpath
- fpath = reverse(fpath)
- fname = reverse(fname)
- end
- else if index(fpath,"/") > 0 then do /* relative pathname is specified */
- fpath = reverse(basedir"/"fpath)
- parse fpath fname "/" fpath
- fpath = reverse(fpath)
- fname = reverse(fname)
- end
- else do
- fname = fpath
- fpath = basedir
- end
- call writeln('cf',cdcmd fpath cdopts)
- call writeln('cf',getcmd fname getopts)
- end
- call close('fl')
- end
-
- return error
-
- /*
- * This procedure lets the script grab files via the FTP client using files
- * specified on the command line.
- */
- usefiles:
- parse arg site basedir flist
-
- error = 0
-
- do forever
- parse var flist fpath flist
- if fpath = "" then leave
- if substr(fpath,1,1) = "/" then do /* absolute pathname */
- fpath = reverse(fpath)
- parse fpath fname "/" fpath
- fpath = reverse(fpath)
- fname = reverse(fname)
- end
- else if index(fpath,"/") > 0 then do /* relative pathname is specified */
- fpath = reverse(basedir"/"fpath)
- parse fpath fname "/" fpath
- fpath = reverse(fpath)
- fname = reverse(fname)
- end
- else do
- fname = fpath
- fpath = basedir
- end
- end
- call writeln('cf',cdcmd fpath cdopts)
- call writeln('cf',getcmd fname getopts)
- end
-
- return error
-
- syntax:
- err = rc
- parse source . . . me .
- address AX "ErrorReq ARexx error" err "in line" sigl "of" me"."
- exit
-
- error:
- parse source . . . me .
- address AX "ErrorReq Error" rc "in line" sigl "of" me"."
-