! 20 May 89
! Name:		autop2.cmd
! Usage:	used internally by autopoll.cmd as: 'do autop2 system'
!
! prototype file for automatic reliable polling process autopoll.cmd
! this file can be changed to customize the exact file transfer process

setvar sysname "$1"

retries 2			! 3 file transfer tries total
redial 1			! 2 phone calls per connect attempt

on abort
	log "\^C operator abort"
	? "^C operator abort"
	logfile close
	return
endon

? "Connecting to $(sysname)"
log "Connecting to $(sysname)"
iferror CONNECT $(qdir+sysname)
	? "Connect FAIL system: $(sysname)"
	log "Connect FAIL system: $(sysname)"
	fwriteln 2,sysname	! error - write system name to outfile
	return
endif

iferror STARTSERVER
	noerror HANGUP
	return
endif

wait 1				! required for TERMCRC protocol

! the for loop below reads all requests for this system
! and executes them as term scripts.  The requests typically
! contain a single XFER or GET statement.  Each system request
! is in a file named sysname.nnn where sysname is the system name,
! and nnn is a per-sysname sequence number, starting at 000.
setvar waserror FALSE
for request in ($(qdir+sysname+qext)) do
	if tolower(right(request,len(nodeext))) != nodeext
		iferror DO $(request)
			? "Request '$(request)' FAIL system: $(sysname)"
			log "Request '$(request)' FAIL system: $(sysname)"
			setvar waserror TRUE
		endif
	endif
endfor
if waserror
	fwriteln 2,sysname	! error - write system name to outfile
endif

!
! uncomment the following line to terminate MSDOS TERM servers permanently
!remote quit

noerror STOPSERVER
wait 1
noerror HANGUP

return
