;FileXfer_Client.WAS     v1.0

;*****************************************************************************
;*                                                                           *
;* FileXfer_Client.WAS                                                       *
;* Copyright (C) 1998 Symantec                                               *
;* All rights reserved.                                                      *
;*                                                                           *
;* Written by:  Symantec ASPECT Assist                                       *
;* 01/07/97                                                                  *
;*                                                                           *                                                                             
;* This script file works with FileXfer_Host.WAS.  This script calls the     *
;* Host, and uploads and downloads files from the host, and puts them in     *
;* proper directories as defined in the DEFINE section of the script.        *
;*                                                                           *
;* 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.                         *                                                                          
;*                                                                           *
;*****************************************************************************


;*******************************************************************************
;* Define                                                                      * 
;*******************************************************************************
#define PhoneNumber "1,999-999-9999"      ;The phone number to dial.
#define OutBoxDir "c:\export\"            ;The files to send to host system.
#define OutDone   "c:\export\done\"       ;The dir to move uploaded files.
#define InBox1Dir "c:\import\"            ;The first directory to receive files.
#define InBox2Dir "c:\docs\"              ;The second directory to receive files.

#define LogFile "c:\logfile.txt"          ;The file to store the log info.


;*******************************************************************************
;* Main                                                                        * 
;*******************************************************************************
proc main

   winminimize $PWMAINWIN                      ;Minimize the PW window.
   set modem connection 10                     ;Select the first modem.
   StartProcess()                              ;Start the process.
endproc


;*******************************************************************************
;* StartProcess                                                                * 
;*******************************************************************************
proc StartProcess

   string szMsg
   
   clear                                       ;Clear the screen.

   if fopen 0 LogFile READAPPEND TEXT           ; Open log file for read only.
      logit("***************************************************")
      logit("")
      logit("Starting Process!")
      strfmt szMsg ("Date: %s") $date
      logit(szMsg)
      strfmt szMsg ("Time: %s") $time
      logit(szMsg)
      logit("")
   else
      errormsg "Couldn't open the log file `"%s`"." logFile
   endif

   GoConnect(PhoneNumber)
   GoSendFiles(OutBoxDir)
   GoGetFiles(InBox1Dir)
   GoChange()
   GoGetFiles(InBox2Dir)
   GoFinish()   
    
   logit("Done!")                              ;Update log file.
   logit("")
   logit("***************************************************")
   fclose 0                                    ;Close the log file.
   pwexit
endproc


;*******************************************************************************
;* GoConnect                                                                   * 
;*******************************************************************************
proc GoConnect
param string szNumber

   string szMsg

   dialnumber DATA szNumber                    ;Dial the phone number.
   mspause 500
   while $dialing                              ;Yield while dialing.
      yield
   endwhile
   pause 2
   if $carrier                                 ;If connected.
      transmit "^M^J^M^J"                          ;Transmit CR.
      transmit "Hello^M^J"                       ;Transmit 'Hello'
      if waitfor "Ready" 15                   ;Waitfor 'Ready'
         strfmt szMsg "Connected to system at %s!" szNumber
         logit(szMsg)                          ;Log message to file.
      else
         transmit "Hello^M^J"
         if waitfor "Ready!" 15
            strfmt szMsg "Connected to system at %s!" szNumber
            logit(szMsg)                          ;Log message to file.
         else
            strfmt szMsg "*** Problems talking to system at %s!" szNumber
            logit(szMsg)                          ;Log message to file.
         endif
      endif
   else
      strfmt szMsg "*** Problems making connection to %s!" szNumber
      logit(szMsg)                          ;Log message to file.
   endif
endproc


;*******************************************************************************
;* GoSendFiles                                                                 * 
;*******************************************************************************
proc GoSendFiles
param string szDir

   string szFile, szMsg
   integer iXferTemp
   
   szFile = szDir
   strcat szFile "*.*"                         ;Add the wildcard to path.

   if findfirst szFile                         ;Find first file matching spec.
      sendfile ZMODEM $Filespec                ;Send files in OUTBOX path.
      pause 1
      iXferTemp = $xferstatus
      while iXferTemp == 1                     ;Loop while sending files.
         iXferTemp = $xferstatus
         yield
      endwhile
      if iXferTemp == 2                        ;If files sent successfully.
         strfmt szMsg "File %s sent successfully." $fileSpec
         logit(szMsg)
         szMsg = OutDone
         strcat szMsg $filename
         rename $filespec szMsg
;         delfile $filespec                     ;Delete the sent file.
         
         mspause 500
         strfmt szMsg "File %s moved from OUTBOX." $fileSpec
         logit(szMsg)                          ;Log message to file.
         yield
      else
         strfmt szMsg "*** File %s not sent successfully!" $fileSpec
         logit(szMsg)
      endif
      pause 1
      
      while findnext                           ;If more files exist.
         statmsg "Sending %s" $filespec
         sendfile ZMODEM $Filespec             ;send those files.
         mspause 500
         iXferTemp = $xferstatus
         while iXferTemp == 1
            iXferTemp = $xferstatus            ;Loop while sending files.
            yield
         endwhile
         if iXferTemp == 2                     ;If files send successfully.
            strfmt szMsg "File %s sent successfully." $fileSpec
            logit(szMsg)
            szMsg = OutDone
            strcat szMsg $filename
            rename $filespec szMsg
;            delfile $filespec

            strfmt szMsg "File %s moved from OUTBOX." $fileSpec
            logit(szMsg)                          ;Log message to file.
            mspause 500
            yield
         else
            strfmt szMsg "*** File %s not sent successfully!" $fileSpec
            logit(szMsg)
         endif
      endwhile
   else
      logit("No files to send.")
   endif
   pause 2
   LogIt("Done sending files.")
   transmit "Done sending files!^M^J"                          ;Transmit Done.
   pause 2
endproc

;*******************************************************************************
;* GoGetFiles                                                                  * 
;*******************************************************************************
proc GoGetFiles
param string szDir

   string szDDir

   when $xferstatus call FileStatus
   fetch dnldpath szDDir                       ;Get current path.
   if chdir szDir
      ; path exists.
   else
      errormsg "Path %s does not exist!" szDir
   endif
   set dnldpath szDir                          ;Set download path.
   mspause 250
   set zmodem receiver overwrite SKIP          ;Set overwrite off.
   statmsg "Waiting for files."
   waitfor "Done" forever                      ;Waitfor 'Done' key.
   LogIt("Done receiving files.")
   set dnldpath szDDir                         ;Set download path back.
endproc


;*******************************************************************************
;* GoChange                                                                    * 
;*******************************************************************************
proc GoChange

   pause 5
   transmit "Dir Changed."
   transmit "^M^J"
   logit("Changed receive directory.")
   pause 1
   yield
endproc


;*******************************************************************************
;* FileStatus                                                                  * 
;*******************************************************************************
proc FileStatus

   string szMsg
   if $xferstatus == 2
      strfmt szMsg "File %s received." $xferfile
      LogIt(szMsg)
   endif
endproc


;*******************************************************************************
;* GoFinish                                                                    * 
;*******************************************************************************
proc GoFinish

   when clear
   statmsg "Finished with connection."
   logit("Done with this connection.")
   pause 1
   if $carrier
      hangup                                      ;Hangup the phone line.
      pause 4
   endif
   yield
   clear
   pause 2
endproc


;*******************************************************************************
;* LostCall                                                                    * 
;*******************************************************************************
proc LostCall

   LogIt("Lost Connection!")
   LogIt("")
   statmsg("Lost the connection!")
   GoFinish()
endproc


;*******************************************************************************
;* LogIT                                                                       * 
;*******************************************************************************
proc LogIT
param string szMsg

   fputs 0 szMsg
endproc
