/*--------------------------------------------------*\ This arexx program uses term to download the contents of my /scratch/nsd/autodownload/ directory on uxa It gets term going, has term dial uxa (and the phonebook entry's Login Command is setup to automatically log us into uxa), sets things up for the download, and has uxa send all the files in my autodownload directory to my machine. When the download is finished (or aborted) it deletes the successfully received files from uxa, logs out of uxa and the phone dialup server, hangs up, quits term, and exits. I use it in order to have my Amiga go and download this stuff at 2 o'clock in the morning while I'm sleeping and no one is using my phone line, my computer, the dialup server's modems, etc... . $VER: 1.02 (12.12.93) Nicolas Dade \*--------------------------------------------------*/ /* this port is used by the autologin script to signal us when it is finished and whether it was successfull or not */ portname='autodownload.login.finished' /* get term running */ termfoundrunning='yes' /* remember whether term was already running or not */ IF ~show('ports','TERM') THEN DO termfoundrunning='no' ADDRESS 'COMMAND' 'term:term PORTNAME="TERM" NEW' ADDRESS 'COMMAND' 'WaitForPort TERM' IF rc>0 THEN DO ADDRESS 'COMMAND' 'WaitForPort TERM' /* give it 20 secs to come up */ IF rc>0 THEN DO showerror("Couldn't start term going") EXIT 10 END END ADDRESS 'TERM' 'DELAY MIC 1' /* wait for term to get settled after its arexx port appears */ END ADDRESS 'TERM' /* dial up uxa --- the autologin script that is tied to the phonebook entry will get us to a shell prompt and then send us a message */ IF ~show('L','rexxsupport.library') THEN addlib('rexxsupport.library',0,-30,0) IF ~show('L','rexxsupport.library') THEN DO showerror("Couldn't find rexxsupport.library") abort() END IF ~openport(portname) THEN DO showerror("Couldn't create "portname" port") abort() END CLEAR 'FROM dial' ADDITEM 'TO dial PHONE Mosberg/uxa/autodownload' DIAL /* wait for dialing to have finished */ DELAY 'MIC 1' /* this stuff doesn't work for me; x is left unbound GETATTR 'term.session.online VAR x' SAY 'online is' x /* says: "online is X" */ */ /* wait for autologin to have finished (the autologin script will send us a message) */ DO UNTIL waitpkt(portname) END msg=getpkt(portname) loginresult=getarg(msg,0) reply(msg,0) /* allow the login script to proceed (and exit) */ closeport(portname) IF loginresult~=0 THEN DO showerror("Autologin script was not successfull") abort() END /* the login script takes us all the way to a shell prompt on uxa, so we can start issuing commands right away */ /* turn messages off */ SEND 'mesg n\r' IF waitrc('>',"Didn't get prompt back") THEN abort() SEND 'biff n\r' IF waitrc('>',"Didn't get prompt back") THEN abort() /* move to the autodownload directory */ SEND 'cd /scratch/nsd/autodownload\r' IF waitrc('>',"Didn't get prompt back") THEN abort() /* start the download going */ SEND 'sz -b *\r' RECEIVEFILE 'MODE binary' /* WARNING: THIS HANGS UNTIL IT TIMES OUT IF THERE ARE NO FILES TO SEND */ DELAY 'MIC 1' /* see if uxa is still there by trying to get a prompt */ uxaalive='no' DO i=1 TO 10 UNTIL uxaalive~='no' SEND '\r' TIMEOUT 'SEC 10' WAIT '>' IF rc=0 THEN uxaalive='yes' END IF uxaalive~='yes' THEN DO showerror("uxa seems to no longer be around") abort() END /* delete files that were completely received */ filelistfile='t:autodownload.capture' CLOSE 'FROM file' ADDRESS 'COMMAND' 'delete "'filelistfile'" quiet >nil:' CAPTURE 'TO file NAME "'filelistfile'"' SEND 'ls -l\r' IF waitrc('>',"Didn't get prompt back") THEN abort() CLOSE 'FROM file' OPTIONS RESULTS GETATTR 'OBJECT pathprefs FIELD binarydownloadpath' dlpath=result OPTIONS NO RESULTS IF right(dlpath,1)~=':' & right(dlpath,1)~='/' THEN dlpath=dlpath||'/' IF ~open('filelist',filelistfile,'R') THEN DO showerror("Couldn't open "filelistfile", so no files will be deleted") END ELSE DO DO WHILE ~eof('filelist') l=readln('filelist') IF length(l)>30 & words(l)>4 THEN DO /* filter out non-filelisting lines */ remotename=word(l,words(l)) remotelength=word(l,4) localname=dlpath||remotename IF exists(localname) THEN IF remotelength=word(statef(localname),2) THEN DO SEND 'rm 'remotename'\r' IF waitrc('>',"Didn't get prompt back") THEN abort() END END END close('filelist') ADDRESS 'COMMAND' 'delete "'filelistfile'" quiet' END /* logout and exit */ SEND 'logout\r' IF waitrc('>',"couldn't logout of uxa and get back to the terminal server") THEN abort() SEND 'logout\r' HANGUP IF termfoundrunning='no' THEN QUIT 'FORCE' EXIT 0 /*--------------------------------------*/ waitrc: /* (waitstring, errorstring) */ PARSE ARG waitstring,errorstring TIMEOUT 'SEC 10' WAIT '"'waitstring'"' IF rc=0 THEN DO RETURN 0 END ELSE DO showerror(errorstring) abort() END showerror: /* (errorstring) */ PARSE ARG errorstring SAY 'AutoDownload ERROR: 'errorstring RETURN 0 abort: /* get out of here, leaving a record of what went wrong */ SAVEAS 'NAME t:autodownload.FAILED.buffer FROM buffer' HANGUP IF termfoundrunning='no' THEN QUIT 'FORCE' EXIT 10