;FileXmit_Send.WAS  v1.0

;*****************************************************************************
;*                                                                           *
;* FileXmit_Send.WAS                                                         *
;* Copyright (C) 1998 Symantec                                               *
;* All rights reserved.                                                      *
;*                                                                           *
;* Written by:  Symantec ASPECT Assist                                       *
;* 09/23/98                                                                  *
;*                                                                           *
;* Program to upload 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 "c:\xxx\xxx.txt"         ;holds 1st path/file to upload
#DEFINE FILENAME2 "c:\xxx\xxxxxxxl.txt"    ;holds 2nd path/file to upload
#DEFINE FILENAME3 "xxx.xxx"                ;holds 3rd path/file to upload
#DEFINE NUM_FILES "2"                      ;change to number of files to upload
#DEFINE CR "^M"                            ;defines carriage return


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

string FileForRemote1 = "remote1"
string FileForRemote2 = "remote2"
string FileForRemote3 = "remote3"


;*****************************************************************************
;*                                                                           *
;* 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: PLACECALL, LOGIN, TRANSFERFILES                                    *
;* Modifies globals: NONE                                                    *
;*                                                                           *
;*****************************************************************************

proc Main

   when TARGET 0 "Login incorrect" call ErrProc

   PlaceCall()                             ;calls procedure to place the call
   Login()                                 ;calls the login procedure
   TransferFiles()                         ;calls procedure to transfer files
   
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
   if !$CARRIER
      usermsg "Did not establish carrier.  Please try again."
      exit                           ;exits the script file
   endif
   
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 sends the files from the remote system.       *
;*                                                                           *
;* Calls: NONE                                                               *
;* Called by: MAIN                                                           *
;* Modifies globals: FILEFORREMOTE1, FILEFORREMOTE2, FILEFORREMOTE3          *
;*                                                                           *
;*****************************************************************************

proc TransferFiles

integer Flag
integer TransferStat
string TransferCmd
   
   for i0 = 1 upto NUM_FILES
      switch i0
         case 1
            Xfer1:
            strfmt TransferCmd "$$add bid='%s'" FileForRemote1
            transmit TransferCmd            ;transfer the transfer command
            transmit CR                     ;send a carriage return
            pause 5                         ;wait for system to process command
            strfmt TransferCmd "%s" FILENAME1
            sendfile XMODEM TRANSFERCMD     ;send the file via XMODEM
            Flag = 1                        ;set flag = 1
         endcase
         case 2
            Xfer2:
            strfmt TransferCmd "$$add bid='%s'" FileForRemote2
            transmit TransferCmd            ;transfer the transfer command
            transmit CR                     ;send a carriage return
            pause 5                         ;wait for system to process command
            strfmt TransferCmd "%s" FILENAME2
            sendfile XMODEM TRANSFERCMD     ;send the file via XMODEM
            Flag = 2                        ;set flag = 2
         endcase
         case 3
            Xfer3:
            strfmt TransferCmd "$$add bid='%s'" FileForRemote3
            transmit TransferCmd            ;transfer the transfer command
            transmit CR                     ;send a carriage return
            pause 5                         ;wait for system to process command
            strfmt TransferCmd "%s" FILENAME3
            sendfile XMODEM TRANSFERCMD     ;send 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
   endfor
   waitfor "cmd>" 5                         ;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
   dialogbox 0 150 132 138 20 1
      text 1 35 5 69 8 "Files sent to HOST." left
   enddialog
   pause 180
   dlgdestroy 0 CANCEL
   pwexit                                   ;exits Procomm Plus

endproc


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

proc ErrProc

   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