home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 3 Comm / 03-Comm.zip / autozoc3.zip / GETFILES.REX < prev    next >
OS/2 REXX Batch file  |  1996-09-01  |  11KB  |  451 lines

  1. /* REXX script to automatically call BBS, log on, download up to TEN files, then log off. */
  2.  
  3. /* clear screen  */
  4. CALL ZocCls
  5.  
  6. /* set variables */
  7.  
  8. user_name="XXXX XXXXXXXX"       /* your name as registered with the BBS (put in quotes) */
  9. password="XXX##XX"              /* your password as registered with the BBS (put in quotes) */
  10. bbs_num="#-###-###-####"        /* the BBS phone number (put in quotes) */
  11. min_speed=#####                 /* minimum connect speed you'll accept (NO QUOTES) */
  12. max_attempts=#                  /* maximum number of times to retry the call (NO QUOTES) */
  13.  
  14. CR=d2c(13)
  15. qty_files=0
  16. org_qty=0
  17. reply=""
  18. answer=""
  19.  
  20. CALL GET_FILE_NAMES
  21.  
  22. CALL FILE_NAME_CONFIRM
  23.  
  24. DO call_bbs=1 TO max_attempts
  25.  
  26.   /* clear screen */
  27.   CALL ZocCls
  28.  
  29.   /* initialize modem */
  30.   CALL ZocSend "ATZ1^M"
  31.   CALL ZocDelay 1
  32.  
  33.   SAY "Attempt # " call_bbs 
  34.  
  35.   SAY "Calling the OS/2 Shareware BBS to download files.  Dialing...." bbs_num
  36.  
  37.   CALL ZocTimeOut 60
  38.  
  39.   DIAL bbs_num '^IOS/2 Shareware'
  40.  
  41.       /* let's see what kind of response we get */
  42.       DO result_type=1 TO 6
  43.  
  44.          
  45.          /* receive next line of text */
  46.          rc=ZocGetLine()
  47.  
  48.          /* if no answer, try again (leave loop) */
  49.          IF rc=640 THEN 
  50.          DO
  51.             CALL ZocHangup
  52.             LEAVE result_type
  53.          END
  54.          
  55.          /* if BUSY was received, try again (leave loop) */
  56.          IF ZocLastLine()="BUSY" THEN
  57.          DO
  58.         CALL ZocDelay 1
  59.         CALL ZocMsgBox "The line is busy.  We'll try again.", 0
  60.             LEAVE result_type
  61.          END
  62.  
  63.          /* if NO DIAL TONE was received, end with error message */
  64.          IF ZocLastLine()="NO DIAL TONE" THEN 
  65.          DO
  66.         CALL ZocDelay 1
  67.             CALL ZocMsgBox "Possible hardware or software trouble.  Aborting attempt.", 1
  68.             EXIT
  69.          END
  70.  
  71.          /* if NO CARRIER was received, end with error message */
  72.          IF ZocLastLine()="NO CARRIER" THEN 
  73.          DO
  74.             CALL ZocHangup
  75.             CALL ZocMsgBox "Possible dialing error.  Check phone number.", 1
  76.             EXIT
  77.          END
  78.  
  79.          /* determine the connect speed */
  80.          DO b=9 TO 15
  81.            IF SUBSTR(ZocLastLine(),b,1)="/" THEN
  82.            DO 
  83.               b=b-9
  84.               LEAVE b
  85.            END
  86.          END b
  87.          speed=SUBSTR(ZocLastLine(),9,b)
  88.          IF speed<min_speed THEN 
  89.          DO
  90.             CALL ZocHangup
  91.             ans=ZocMsgBox("Connect speed is too slow!  Do you want to try again?", 2)
  92.             IF ans="##NO##" THEN EXIT
  93.                ELSE LEAVE result_type
  94.          END
  95.          ELSE LEAVE call_bbs
  96.  
  97.       END result_type
  98.  
  99.       IF call_bbs<max_attempts THEN
  100.       DO
  101.     DO time_out=30 to 1 by -1
  102.       IF time_out>1 THEN CALL ZocNotify "Pausing " time_out " seconds."
  103.          ELSE CALL ZocNotify "Pausing " time_out " second."
  104.       Call ZocDelay 1
  105.     END time_out
  106.       END
  107.  
  108. END call_bbs
  109.  
  110. IF call_bbs=max_attempts+1 THEN
  111. DO
  112.    CALL ZocMsgBox "Can't get through now.....try again later.", 0
  113.    CALL ZocCls
  114.    CALL ZocSend "ATZ1^M"
  115.    CALL ZocDelay 1
  116.    EXIT
  117. END
  118.  
  119. CALL ZocTimeOut 10
  120. rc=ZocGetLine()
  121. IF rc=640 THEN SIGNAL PROBLEM
  122.  
  123. CALL ZocWait 'your name:'
  124. CALL ZocSend user_name '^M'
  125.  
  126. CALL ZocTimeOut 05
  127. rc=ZocGetLine()
  128. IF rc=640 THEN SIGNAL PROBLEM
  129.  
  130. CALL ZocWait SUBSTR(user_name,LENGTH(user_name)-2,3)' [Y,n]?'
  131. CALL ZocSend 'y^M'
  132.  
  133. CALL ZocTimeOut 05
  134. rc=ZocGetLine()
  135. IF rc=640 THEN SIGNAL PROBLEM
  136.  
  137. CALL ZocWait 'Password:'
  138. CALL ZocSend PASSWORD '^M'
  139.  
  140. CALL ZocTimeOut 05
  141. rc=ZocGetLine()
  142. IF rc=640 THEN SIGNAL PROBLEM
  143.  
  144. CALL ZocWait 'o continue'
  145. CALL ZocSend '^M'
  146.  
  147. CALL ZocTimeOut 05
  148. rc=ZocGetLine()
  149. IF rc=640 THEN SIGNAL PROBLEM
  150.  
  151. CALL ZocWait 'e [Y,n,=]?'
  152. CALL ZocSend 'N^M'
  153.  
  154. CALL ZocTimeOut 05
  155. rc=ZocGetLine()
  156. IF rc=640 THEN SIGNAL PROBLEM
  157.  
  158. CALL ZocWait 'Select: '
  159. CALL ZocSend 'F^M'
  160.  
  161. CALL ZocTimeOut 05
  162. rc=ZocGetLine()
  163. IF rc=640 THEN SIGNAL PROBLEM
  164.  
  165. CALL ZocWait 'Select: '
  166. CALL ZocSend 'D^M'
  167.  
  168. CALL ZocTimeOut 6000
  169.  
  170. DO file_names=1 TO 100
  171.     IF qty_files>=2 THEN
  172.     DO  
  173.        CALL ZocWait 'load (#1):'
  174.        CALL ZocSend file_A '^M'
  175.     END
  176.     ELSE LEAVE file_names
  177.   IF qty_files>=3 THEN
  178.     DO  
  179.        CALL ZocWait 'load (#2):'
  180.        CALL ZocSend file_B '^M'
  181.     END
  182.     ELSE LEAVE file_names
  183.   IF qty_files>=4 THEN
  184.     DO  
  185.        CALL ZocWait 'load (#3):'
  186.        CALL ZocSend file_C '^M'
  187.     END
  188.     ELSE LEAVE file_names
  189.   IF qty_files>=5 THEN
  190.     DO  
  191.        CALL ZocWait 'load (#4):'
  192.        CALL ZocSend file_D '^M'
  193.     END
  194.     ELSE LEAVE file_names
  195.   IF qty_files>=6 THEN
  196.     DO  
  197.        CALL ZocWait 'load (#5):'
  198.        CALL ZocSend file_E '^M'
  199.     END
  200.     ELSE LEAVE file_names
  201.   IF qty_files>=7 THEN
  202.     DO  
  203.        CALL ZocWait 'load (#6):'
  204.        CALL ZocSend file_F '^M'
  205.     END
  206.     ELSE LEAVE file_names
  207.   IF qty_files>=8 THEN
  208.     DO  
  209.        CALL ZocWait 'load (#7):'
  210.        CALL ZocSend file_G '^M'
  211.     END
  212.     ELSE LEAVE file_names
  213.   IF qty_files>=9 THEN
  214.     DO  
  215.        CALL ZocWait 'load (#8):'
  216.        CALL ZocSend file_H '^M'
  217.     END
  218.     ELSE LEAVE file_names
  219.   IF qty_files>=10 THEN
  220.     DO  
  221.        CALL ZocWait 'load (#9):'
  222.        CALL ZocSend file_I '^M'
  223.     END
  224.     ELSE LEAVE file_names
  225.   IF qty_files>=11 THEN
  226.     DO  
  227.        CALL ZocWait 'load (#10):'
  228.        CALL ZocSend file_J '^M'
  229.     END
  230.     ELSE LEAVE file_names
  231. END file_names
  232.  
  233. CALL ZocWait 'load (#'qty_files'):'
  234. CALL ZocSend '/G^M'
  235.  
  236. CALL ZocWait '<esc> to abort:'
  237. CALL ZocSend '^M'
  238.  
  239. EXIT
  240.  
  241.  
  242. GET_FILE_NAMES:
  243.  
  244.   CALL ZocCls
  245.  
  246.   file_A=""
  247.   file_B=""
  248.   file_C=""
  249.   file_D=""
  250.   file_E=""
  251.   file_F=""
  252.   file_G=""
  253.   file_H=""
  254.   file_I=""
  255.   file_J=""
  256.  
  257.   /* Ask user for first file name */
  258.   answer=ZocAsk("Enter file name to download.")
  259.  
  260.   IF answer="##CANCEL##" THEN
  261.   DO
  262.     CALL ZocSend "ATZ1^M"
  263.     CALL ZocNotify "Operation cancelled."
  264.     EXIT
  265.   END
  266.  
  267.   IF answer="" THEN
  268.   DO
  269.     CALL ZocSend "ATZ1^M"
  270.     CALL ZocNotify "Operation cancelled."
  271.     EXIT
  272.   END
  273.  
  274.   file_A=answer
  275.   SAY "File # 1 - "file_A
  276.  
  277.   /* ask for maximum of 9 more file names */
  278.   DO qty_files=2 to 10
  279.  
  280.     /* Ask user for file name */
  281.     answer=ZocAsk("Enter file name to download.")
  282.  
  283.     IF answer="" THEN LEAVE qty_files
  284.   
  285.     IF answer="##CANCEL##" THEN
  286.     DO
  287.       org_qty=qty_files
  288.       qty_files=100
  289.       reply=ZocMsgBox("Are you sure you want to cancel?",2)
  290.       IF reply="##YES##" THEN
  291.       DO
  292.         CALL ZocCls
  293.         CALL ZocSend "ATZ1^M"
  294.         CALL ZocNotify "Operation cancelled."
  295.         EXIT
  296.       END
  297.     END
  298.  
  299.     IF qty_files=2 THEN 
  300.     DO 
  301.       file_B=answer
  302.       SAY "File # 2 - "file_B
  303.     END
  304.     IF qty_files=3 THEN
  305.     DO
  306.       file_C=answer
  307.       SAY "File # 3 - "file_C
  308.     END
  309.     IF qty_files=4 THEN
  310.     DO
  311.       file_D=answer
  312.       SAY "File # 4 - "file_D
  313.     END
  314.     IF qty_files=5 THEN
  315.     DO
  316.       file_E=answer
  317.       SAY "File # 5 - "file_E
  318.     END
  319.     IF qty_files=6 THEN
  320.     DO
  321.       file_F=answer
  322.       SAY "File # 6 - "file_F
  323.     END
  324.     IF qty_files=7 THEN
  325.     DO
  326.       file_G=answer
  327.       SAY "File # 7 - "file_G
  328.     END
  329.     IF qty_files=8 THEN
  330.     DO
  331.       file_H=answer
  332.       SAY "File # 8 - "file_H
  333.     END
  334.     IF qty_files=9 THEN
  335.     DO
  336.       file_I=answer
  337.       SAY "File # 9 - "file_I
  338.     END
  339.     IF qty_files=10 THEN
  340.     DO
  341.       file_J=answer
  342.       SAY "File # 10 - "file_J
  343.     END
  344.  
  345.     IF qty_files=100 THEN qty_files=org_qty-1
  346.       
  347.   END qty_files
  348.  
  349. RETURN
  350.  
  351. FIX_FILE_NAMES:
  352.  
  353.   fix_reply=ZocAsk("Enter file NUMBER that is incorrect.")
  354.  
  355.   SELECT
  356.     WHEN fix_reply="##CANCEL##" THEN RETURN
  357.     WHEN fix_reply="" THEN RETURN
  358.     WHEN fix_reply=1 THEN DO
  359.       answer=ZocAsk("Enter file name to download.")
  360.       IF answer="##CANCEL##" THEN RETURN
  361.       IF answer="" THEN RETURN
  362.       file_A=answer
  363.       END
  364.     WHEN fix_reply=2 THEN DO
  365.       answer=ZocAsk("Enter file name to download.")
  366.       IF answer="##CANCEL##" THEN RETURN
  367.       IF answer="" THEN RETURN
  368.       file_B=answer
  369.       END
  370.     WHEN fix_reply=3 THEN DO
  371.       answer=ZocAsk("Enter file name to download.")
  372.       IF answer="##CANCEL##" THEN RETURN
  373.       IF answer="" THEN RETURN
  374.       file_C=answer
  375.       END
  376.     WHEN fix_reply=4 THEN DO
  377.       answer=ZocAsk("Enter file name to download.")
  378.       IF answer="##CANCEL##" THEN RETURN
  379.       IF answer="" THEN RETURN
  380.       file_D=answer
  381.       END
  382.     WHEN fix_reply=5 THEN DO
  383.       answer=ZocAsk("Enter file name to download.")
  384.       IF answer="##CANCEL##" THEN RETURN
  385.       IF answer="" THEN RETURN
  386.       file_E=answer
  387.       END
  388.     WHEN fix_reply=6 THEN DO
  389.       answer=ZocAsk("Enter file name to download.")
  390.       IF answer="##CANCEL##" THEN RETURN
  391.       IF answer="" THEN RETURN
  392.       file_F=answer
  393.       END
  394.     WHEN fix_reply=7 THEN DO
  395.       answer=ZocAsk("Enter file name to download.")
  396.       IF answer="##CANCEL##" THEN RETURN
  397.       IF answer="" THEN RETURN
  398.       file_G=answer
  399.       END
  400.     WHEN fix_reply=8 THEN DO
  401.       answer=ZocAsk("Enter file name to download.")
  402.       IF answer="##CANCEL##" THEN RETURN
  403.       IF answer="" THEN RETURN
  404.       file_H=answer
  405.       END
  406.     WHEN fix_reply=9 THEN DO
  407.       answer=ZocAsk("Enter file name to download.")
  408.       IF answer="##CANCEL##" THEN RETURN
  409.       IF answer="" THEN RETURN
  410.       file_I=answer
  411.       END
  412.     WHEN fix_reply=10 THEN DO
  413.       answer=ZocAsk("Enter file name to download.")
  414.       IF answer="##CANCEL##" THEN RETURN
  415.       IF answer="" THEN RETURN
  416.       file_J=answer
  417.       END
  418.     OTHERWISE CALL ZocMsgBox "You made an improper entry!"||CR fix_reply " is not a correct responce."||CR "Enter the file NUMBER that is incorrect.", 1
  419.   END /* select */
  420.  
  421.   CALL ZocCls
  422.  
  423.   SAY "File # 1 - "file_A
  424.   IF qty_files>2 THEN SAY "File # 2 - "file_B
  425.   IF qty_files>3 THEN SAY "File # 3 - "file_C
  426.   IF qty_files>4 THEN SAY "File # 4 - "file_D
  427.   IF qty_files>5 THEN SAY "File # 5 - "file_E
  428.   IF qty_files>6 THEN SAY "File # 6 - "file_F
  429.   IF qty_files>7 THEN SAY "File # 7 - "file_G
  430.   IF qty_files>8 THEN SAY "File # 8 - "file_H
  431.   IF qty_files>9 THEN SAY "File # 9 - "file_I
  432.   IF qty_files>10 THEN SAY "File # 10 - "file_J
  433.  
  434.   CALL FILE_NAME_CONFIRM
  435.  
  436. RETURN
  437.  
  438.  
  439. FILE_NAME_CONFIRM:
  440.  
  441.   ans=ZocMsgBox("Is the list of files shown correct?", 2)
  442.   IF ans="##NO##" THEN CALL FIX_FILE_NAMES
  443.  
  444. RETURN
  445.  
  446.  
  447. PROBLEM:
  448.    CALL ZocHangup
  449.    CALL ZocMsgBox "Something went wrong", 1
  450.    EXIT
  451.