;* Retries a busy FTP site until connected.

;*****************************************************************************
;* Written by:  Symantec ASPECT Assist                                       *
;*                                                                           *                                                                             
;* This script file will give the user the option of either capturing data   *
;* in half hour increments, or in 24 hour increments. The Capture file will  *
;* close after a predefined period of inactivity on the port.                *
;*                                                                           *
;* 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.                         *                                                                          *
;*****************************************************************************



;*****************************************************************************
;* MAIN                                                                      *
;* The Main procedure calls GetAddress when an FTP connection is made.       *
;*                                                                           *
;*            Calls: GetAddress                                              *
;* Modifies globals: <None>                                                  *
;*****************************************************************************

proc Main
   when $IPADDRESS call GetAddress          ;When the IP address changes,
                                            ;  start the retry process.
   while 1                                  ;Loop forever
      yield                                 ;Yield processor time to other processes
   endwhile   
endproc


;*****************************************************************************
;* GetAddress()                                                              *
;* The procedure GetAddress gets the address to which the user is connecting.*
;* It then calls the DoRetry procedure to retry the connection.
;*                                                                           *
;*            Calls:  DoRetry                                                *
;*        Called by:  Main                                                   *
;*****************************************************************************

proc GetAddress

   string szTryAddress                    ;Retry address
   
   szTryAddress = $IPADDRESS              ;Get current IP address
   if strcmp szTryAddress ""              ;If not currently connecting
      return                              ;Return to Main procedure.
   endif
   while $FTPCONNECT == 1                 ;Loop here while connecting
      yield
   endwhile
   pause 1                                ;Wait for connection to finish
   DoRetry(szTryAddress)                  ;Begin retrying
endproc


;*****************************************************************************
;* DoRetry(string)                                                           *
;* This procedure loops as long as there is no FTP connection established.   *
;* With each loop, it tries to establish a connection to the address passed  *
;* to it.                                                                    *
;*                                                                           *
;*            Calls:  ExitScript                                             *
;*        Called by:  GetAddress                                             *
;*****************************************************************************

proc DoRetry
   param string szTryAddress              ;Address to retry

   string szDialogMsg                     ;Dialog box message
   
   strfmt szDialogMsg "Retrying %s" szTryAddress
   dialogbox 0 158 136 198 64 7 "FTP Retry"    ;Cancel dialog
      text 1 8 14 176 8 szDialogMsg center
      pushbutton 2 77 38 40 14 "&Cancel" cancel default
   enddialog
   when dialog 0 call ExitScript
   
   while $FTPCONNECT != 2                 ;Loop while not connected
      connectmanual FTP szTryAddress      ;Try to establish FTP connection
      pause 1                             ;Wait for connection to begin
      while $FTPCONNECT == 1              ;Loop here while connecting
         yield
      endwhile
      pause 1
   endwhile
   exit
endproc


;*****************************************************************************
;* ExitScript()                                                              *
;* This procedure is called when the user hits "Cancel" on the FTP Retry     *
;* dialog to exit the script.                                                *
;*                                                                           *
;*            Calls:  <None>                                                 *
;*        Called by:  DoRetry                                                *
;*****************************************************************************

proc ExitScript

   integer Event             ;Dialog event number
   
   dlgevent 0 Event          ;Get the event number that triggered this procedure
   switch Event  
      case 2                 ;If the "Cancel" button was pressed
         exit                ;Exit the script
      endcase
      default                ;If anything else triggered this procedure, 
      endcase                ;   return to DoRetry
   endswitch
endproc