;FileXmit_Receive.WAS  v1.0

;*****************************************************************************
;*                                                                           *
;* FileXmit_Receive.WAS                                                      *
;* Copyright (C) 1998 Symantec                                               *
;* All rights reserved.                                                      *
;*                                                                           *
;* Written by:  Symantec ASPECT Assist                                       *
;* 9/21/98                                                                   *
;*                                                                           *
;* Program to download a series of files from remote machine.                *
;*                                                                           *
;* This ASPECT script is intended only as a sample of ASPECT programming.    *
;* Symantec makes no warranty of any kind, express or implied, including     *
;* without limitation, any warranties of merchantability and/or fitness      *
;* for a particular purpose.  Use of this program is at your own risk.       *
;*                                                                           *
;* Technical Support is not provided on this script.                         *                                                                          
;*                                                                           *
;*****************************************************************************

;*****************************************************************************
;*   MACRO DEFINITIONS                                                       *
;*****************************************************************************

#DEFINE PHONE_NUM "8,1-999-999-9999" ;holds phone number to dial
#DEFINE LOGIN_ID "NAME"              ;holds login id
#DEFINE PASS_WORD "passwd"           ;holds the password
#DEFINE FILENAME1 "file1"            ;holds 1st file to dnload
#DEFINE FILENAME2 "file2"            ;holds 2nd file to dnload
#DEFINE FILENAME3 "xxxxxxx"          ;holds third file to dnload
#DEFINE NUM_FILES 2                  ;change to number of files to dnload
#DEFINE CR "^M"                      ;defines carriage return

;*****************************************************************************
;*   GLOBAL VARIABLES                                                        *
;*****************************************************************************

integer ExitFlag = 1                 ;set exit flag to 1

;*****************************************************************************
;*                                                                           *
;* MAIN                                                                      *
;* The Main procedure calls PlaceCall to dial the phone number, calls        *
;* Login to login to remote machine, and calls TransferFiles to transfer     *
;* the files to the remote machine.                                          *
;*                                                                           *
;* Calls: ERRPROC, PLACECALL, LOGIN, TRANSFERFILES                           *
;* Modifies globals: NONE                                                    *
;*                                                                           *
;*****************************************************************************

proc Main

   when TARGET 0 "*** ERROR" call ErrProc
   when TARGET 1 "Login incorrect" call ErrProc2

   while ExitFlag   
      PlaceCall()
      Login()
      TransferFiles()
   endwhile
   
endproc


;*****************************************************************************
;*                                                                           *
;* PLACECALL()                                                               *
;* The procedure PlaceCall calls remote system.                              *
;*                                                                           *
;* Calls: NONE                                                               *
;* Called by: MAIN                                                           *
;* Modifies globals: NONE                                                    *
;*                                                                           *
;*****************************************************************************

proc PlaceCall

   dialnumber DATA PHONE_NUM         ;dials the phone number
   while $DIALING                    ;loops while dialing number
   endwhile
   
endproc   


;*****************************************************************************
;*                                                                           *
;* LOGIN()                                                                   *
;* The procedure Login logs into the remote system.                          *
;*                                                                           *
;* Calls: NONE                                                               *
;* Called by: MAIN                                                           *
;* Modifies globals: NONE                                                    *
;*                                                                           *
;*****************************************************************************

proc Login

   transmit CR                       ;sends carriage return to remote system
   waitfor "logon id"                ;waits for login id prompt
   if FAILURE
      usermsg "Login prompt not received.  Try again."
      hangup                         ;hangs up the phone line
      pause 2                        ;waits two seconds
      exit                           ;exits the script file
   else
      transmit LOGIN_ID              ;transmits the login id
      transmit CR                    ;sends Carriage Return to remote
   endif
   waitfor "password"                ;waits for the password prompt
   if FAILURE
      usermsg "Password prompt not received.  Try again."
      hangup                         ;hangs up the phone line
      pause 2                        ;waits two seconds
      exit                           ;exits the script file
   else
      transmit PASS_WORD             ;transmits the Password to remote
      transmit CR                    ;sends Carriage return to remote
   endif
   waitfor "cmd>"                    ;waits for the command prompt
   if FAILURE
      usermsg "Command prompt not received.  Try again."
      hangup                         ;hangs up the phone line
      pause 2                        ;waits two seconds
      exit                           ;exits the script file
   endif
   
endproc


;*****************************************************************************
;*                                                                           *
;* TRANSFERFILES()                                                           *
;* The procedure TransferFiles receives the files from the remote system.    *
;*                                                                           *
;* Calls: NONE                                                               *
;* Called by: MAIN                                                           *
;* Modifies globals: NONE                                                    *
;*                                                                           *
;*****************************************************************************
      
proc TransferFiles

integer Flag
integer TransferStat
string TransferCmd
   
   for i0 = 1 upto NUM_FILES
      switch i0
         case 1
            Xfer1:
            strfmt TransferCmd "$$req bid='%s'" FILENAME1
            transmit TransferCmd            ;transfer the transfer command
            transmit CR                     ;send a carriage return
            pause 5                         ;wait for system to process command
            strfmt TransferCmd "%s.txt" FILENAME1
            pause 5
            if ExitFlag == 2
               goto EndTransfer
            endif
            if ! $CARRIER
               goto EndTransfer
            endif
            getfile XMODEM TRANSFERCMD      ;get the file via XMODEM
            Flag = 1                        ;set flag = 1
         endcase
         case 2
            Xfer2:
            strfmt TransferCmd "$$req bid='%s'" FILENAME2
            transmit TransferCmd            ;transfer the transfer command
            transmit CR                     ;send a carriage return
            pause 5                         ;wait for system to process command
            strfmt TransferCmd "%s.txt" FILENAME2
            if ! $CARRIER
               goto EndTransfer
            endif
            getfile XMODEM TRANSFERCMD      ;get the file via XMODEM
            Flag = 2                        ;set flag = 2
         endcase
         case 3
            Xfer3:
            strfmt TransferCmd "$$req bid='%s'" FILENAME3
            transmit TransferCmd            ;transfer the transfer command
            transmit CR                     ;send a carriage return
            pause 5                         ;wait for system to process command
            strfmt TransferCmd "%s.txt" FILENAME3
            if ! $CARRIER
               goto EndTransfer
            endif
            getfile XMODEM TRANSFERCMD      ;get the file via XMODEM
            Flag = 3                        ;set flag = 3
         endcase
      endswitch
      TransferStat = 1
      while TransferStat
         TransferStat = $XFERSTATUS
         if TransferStat == 3               ;if transfer unsuccessful
            switch Flag                     ;Check to see what File we are on
               case 1                       ;FileName 1
                  Flag = 0                  ;reset flag
                  goto Xfer1                ;go back to xfer 1
               endcase
               case 2                       ;FileName 2
                  Flag = 0                  ;reset flag
                  goto Xfer2                ;go back to xfer 2
               endcase
               case 3                       ;FileName 3
                  goto Xfer3                ;go back to xfer 3
               endcase
            endswitch
         endif
      endwhile
      if ! $CARRIER
         goto EndTransfer
      endif
   endfor
   waitfor "cmd>"                           ;waits for command prompt
   transmit "$$logoff"                      ;transmits the logoff command
   transmit CR                              ;transmits a carriage return
   hangup                                   ;transmits the hangup command
   pause 2                                  ;waits 2 seconds
   pwexit                                   ;exit Procomm on success 
   EndTransfer:   
   hangup                                   ;hangs up phone line if file not 
                                            ;available
   pause 240                                ;pauses for 4 minutes
endproc


;*****************************************************************************
;*                                                                           *
;* ERRPROC()                                                                 *
;* The procedure ERRPROC logs off remote system if error message was received*
;*                                                                           *
;* Calls: NONE                                                               *
;* Called by: MAIN                                                           *
;* Modifies globals: NONE                                                    *
;*                                                                           *
;*****************************************************************************

proc ErrProc

   dialogbox 0 89 132 252 20 1
      text 1 22 5 206 8 "File not ready.  Press OK and script will try again in 5 minutes!" left
   enddialog
   pause 60
   dlgdestroy 0 CANCEL
   transmit "$$logoff"                ;send the logoff command
   transmit CR                        ;send a carriage return
   hangup                             ;hangup the phone line
   pause 2                            ;pause for hangup
   ExitFlag = 2                       ;set Exit flag to 2

endproc


;*****************************************************************************
;*                                                                           *
;* ERRPROC2()                                                                *
;* The procedure ERRPROC2 logs off remote system if error message was        *
;* received.                                                                 *
;*                                                                           *
;* Calls: NONE                                                               *
;* Called by: MAIN                                                           *
;* Modifies globals: NONE                                                    *
;*                                                                           *
;*****************************************************************************

proc ErrProc2

   usermsg "Login Incorrect. . .Please check username and password!"
   transmit "$$logoff"                ;send the logoff command
   transmit CR                        ;send a carriage return
   hangup                             ;hangup the phone line
   pause 2                            ;pause for hangup
   exit                               ;exit the script file

endproc

