home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 2 BBS / 02-BBS.zip / orionful.zip / Menus / Ftp.Cmd < prev    next >
OS/2 REXX Batch file  |  1995-07-31  |  9KB  |  273 lines

  1. /*------------------------------------------------------------------
  2.  * miniftp.cmd :
  3.  *------------------------------------------------------------------
  4.  * 03-16-93 originally by Patrick J. Mueller & Cliff Nadler
  5.  *------------------------------------------------------------------*/
  6.  
  7. ARG line
  8.  
  9.  
  10. STRF_UCASE = X2D(00000001)
  11. STRF_LCASE = X2D(00000002)
  12. STRF_REQUIRED = X2D(00000004)
  13. STRF_NOECHO = X2D(00000008)
  14. STRF_ENCRYPT = X2D(00000010)
  15. STRF_HOT = X2D(00000020)
  16. STRF_EDIT = X2D(00000040)
  17. STRF_PRETTY = X2D(00000080)
  18. STRF_MUSTHOT = X2D(00000100)
  19. STRF_NEAT = X2D(00000200)
  20. STRF_NOHELP = X2D(00000400)
  21. STRF_NOQUE = X2D(00000800)
  22. STRF_NOQUEONE = X2D(00001000)
  23. STRF_CHATCLNT = X2D(00002000)
  24. STRF_NOTIMECHECK = X2D(00004000)
  25.  
  26.     /* types */
  27.  
  28. STRT_ALPHA = 1
  29. STRT_NUMERIC = 2
  30. STRT_ALPHANUMERIC = 3
  31. STRT_HEX = 4
  32. STRT_FILENAME = 5
  33. STRT_FILESPEC = 6
  34. STRT_ALL = 7
  35. STRT_ANY = 8
  36. STRT_YN = 9
  37. STRT_MULTFILES    1 = 0
  38. STRT_MULTSPECS    1 = 1
  39. STRT_YNQ          1 = 2
  40. STRT_YNQS         1 = 3
  41. STRT_JUSTFILE     1 = 4
  42. STRT_MULTJUST     1 = 5
  43. STRT_TELEPHONE    1 = 6
  44. STRT_YNNUM        1 = 7
  45.  
  46.  
  47.  
  48.  
  49. /*------------------------------------------------------------------
  50.  * load functions, if needed
  51.  *------------------------------------------------------------------*/
  52. if RxFuncQuery("FtpLoadFuncs") then
  53.    do
  54.    rc = RxFuncAdd("FtpLoadFuncs","RxFtp","FtpLoadFuncs")
  55.    rc = FtpLoadFuncs()
  56.    end
  57.  
  58. if RxFuncQuery("SysLoadFuncs") then
  59.    do
  60.    rc = RxFuncAdd("SysLoadFuncs","RexxUtil","SysLoadFuncs")
  61.    rc = SysLoadFuncs()
  62.    end
  63.  
  64. /*------------------------------------------------------------------
  65.  * set up signal
  66.  *------------------------------------------------------------------*/
  67. rows = 25
  68. cols = 80
  69.  
  70. host = ""
  71. user = ""
  72. pass = ""
  73.  
  74. TEST = ""
  75.  
  76. /*------------------------------------------------------------------
  77.  * set things
  78.  *------------------------------------------------------------------*/
  79.  
  80.  
  81. AdeptPrint(line, "\r\n\n")
  82.  
  83. do while (cmd <> "QUIT")
  84.  
  85.    /*---------------------------------------------------------------
  86.     * print prompt
  87.     *---------------------------------------------------------------*/
  88.    AdeptPrint(line, "\r\nEnter FTP command: (use ? for help)\r\n")
  89.  
  90.    /*---------------------------------------------------------------
  91.     * get command
  92.     *---------------------------------------------------------------*/
  93.    test = AdeptInput(line, 1, 75, STRT_ALL, STRF_EDIT+STRF_NOHELP, "", "", "", "")
  94.  
  95.    parse VAR test cmd cmdargs
  96.  
  97.    parse var cmdargs file1 file2 rest
  98.  
  99.    if (file1 = "") then file1 = "*"
  100.    if (file2 = "") then file2 = file1
  101.  
  102.    /*------------------------------------------------------------------
  103.     * sanity check
  104.     *------------------------------------------------------------------*/
  105.    cmd = translate(cmd)
  106.  
  107.    if (host="") then
  108.       if (cmd <> "CONNECT") & (cmd <> "?") & (cmd <> "QUIT") then
  109.          do
  110.          AdeptPrint(line, "\r\nYou have not provided host, userid, and password information.\r\n")
  111.          AdeptPrint(line, "\r\nUse the CONNECT command to provide this information.\r\n")
  112.          iterate
  113.          end
  114.  
  115.    /*---------------------------------------------------------------
  116.     * start timer for get/put
  117.     *---------------------------------------------------------------*/
  118.    if (cmd = "GET") | (cmd = "GETB") | (cmd = "PUT") | (cmd = "PUTB") then
  119.       call time "r"
  120.  
  121.    /*---------------------------------------------------------------
  122.     * run command
  123.     *---------------------------------------------------------------*/
  124.    err = 0
  125.    select
  126.       when (cmd = "QUIT")    then iterate
  127.       when (cmd = "GET")     then err = FtpGet(file1,file2,"ASCII")
  128.       when (cmd = "GETB")    then err = FtpGet(file1,file2,"BINARY")
  129.       when (cmd = "PUT")     then err = FtpPut(file1,file2,"ASCII")
  130.       when (cmd = "PUTB")    then err = FtpPut(file1,file2,"BINARY")
  131.       when (cmd = "UPUT")    then err = FtpPutUnique(file1,file2,"ASCII")
  132.       when (cmd = "UPUTB")   then err = FtpPutUnique(file1,file2,"BINARY")
  133.       when (cmd = "DELETE")  then err = FtpDelete(file1)
  134.       when (cmd = "RENAME")  then err = FtpRename(file1,file2)
  135.       when (cmd = "APPEND")  then err = FtpAppend(file1,file2,"ASCII")
  136.       when (cmd = "APPENDB") then err = FtpAppend(file1,file2,"BINARY")
  137.       when (cmd = "QUOTE")   then err = FtpQuote(cmdargs)
  138.       when (cmd = "SITE")    then err = FtpSite(cmdargs)
  139.       when (cmd = "CD")      then err = FtpChDir(file1)
  140.       when (cmd = "MD")      then err = FtpMkDir(file1)
  141.       when (cmd = "RD")      then err = FtpRmDir(file1)
  142.  
  143.       when (cmd = "DIR")     then err = FtpDir(file1,"stem.")
  144.       when (cmd = "LS")      then err = FtpLs(file1,"stem.")
  145.  
  146.       when (cmd = "CONNECT") then
  147.          do
  148.          parse var cmdargs host user pass
  149.  
  150.          AdeptPrint(line, "\r\n\nhost = "host"\r\n")
  151.          AdeptPrint(line, "user = "user"\r\n")
  152.          AdeptPrint(line, "pass = "pass"\r\n")
  153.  
  154.          call FtpSetUser host, user, pass
  155.          end
  156.  
  157.       when (cmd = "CLOSE")   then
  158.          do
  159.          rc = FtpLogoff()
  160.          host = ""
  161.          user = ""
  162.          pass = ""
  163.          end
  164.  
  165.       when (cmd = "PWD")     then
  166.          do
  167.          junk = FtpPwd('curdir')
  168.          AdeptPrint(line, "\r\nCurrent Remote Directory :" curdir"\r\n")
  169.          end
  170.  
  171.       when (cmd = "SYS")     then
  172.          do
  173.          junk = FtpSys('sys')
  174.          AdeptPrint(line, "\r\nReturned from sys:" sys"\r\n")
  175.          end
  176.  
  177.       when (cmd = "?")       then call Usage
  178.  
  179.       otherwise
  180.          AdeptPrint(line, "\r\nInvalid command. Use ? for help.\r\n")
  181.    end
  182.  
  183.    /*---------------------------------------------------------------
  184.     * stop timer for get/put
  185.     *---------------------------------------------------------------*/
  186.    if (cmd = "GET") | (cmd = "GETB") | (cmd = "PUT") | (cmd = "PUTB") then
  187.       do
  188.       elapsed = strip(format(time("e"),10,2))
  189.  
  190.       if (cmd = "GET") | (cmd = "GETB") then
  191.          lfile = file2
  192.       else
  193.          lfile = file1
  194.  
  195.       bytes = stream(lfile,"C","QUERY SIZE")
  196.  
  197.       bps = strip(format(bytes/elapsed,10,2))
  198.       AdeptPrint(line, "\r\ntransmitted" bytes "bytes in" elapsed "seconds:" bps "bytes/second.\r\n")
  199.       end
  200.  
  201.    /*------------------------------------------------------------------
  202.     * check error
  203.     *------------------------------------------------------------------*/
  204.    if (err <> 0) then
  205.       AdeptPrint(line, "\r\nError from FTP:" FTPERRNO"\r\n")
  206.  
  207.    /*------------------------------------------------------------------
  208.     * check for dir or ls
  209.     *------------------------------------------------------------------*/
  210.    x = 0
  211.  
  212.    if (cmd = "LS") | (cmd = "DIR") then
  213.       do i = 1 to stem.0
  214.          x = x + 1
  215.          AdeptPrint(line, stem.i"\r\n")
  216.          if(x = 22) then do
  217.             More = AdeptInput(line,,1,,,"More Y/n? ",,,)
  218.             x = 0
  219.             if(More = 'N') then do
  220.               I = stem.0
  221.               Iterate
  222.             end
  223.             if(More = 'n') then do
  224.               I = stem.0
  225.               Iterate
  226.             end
  227.          end
  228.       end
  229. end
  230.  
  231. /*------------------------------------------------------------------
  232.  * quit
  233.  *------------------------------------------------------------------*/
  234. done:
  235. rc = FtpSetUser("X","X","X")
  236. rc = FtpLogoff()
  237. exit
  238.  
  239. /*------------------------------------------------------------------
  240.  * break condition
  241.  *------------------------------------------------------------------*/
  242. halt:
  243.    AdeptPrint(line, "\r\nTerminating ...\r\n")
  244.    signal done
  245.  
  246. /*------------------------------------------------------------------
  247.  * some simple help
  248.  *------------------------------------------------------------------*/
  249. Usage:
  250.  
  251.    AdeptPrint(line, "\r\nusage:\r\n")
  252.    AdeptPrint(line, "   command ...\r\n")
  253.    AdeptPrint(line, "is used to run ftp commands on a remote host\r\n\n")
  254.    AdeptPrint(line, "where:\r\n")
  255.    AdeptPrint(line, "   command can be one of:\r\n")
  256.    AdeptPrint(line, "       connect host user password\r\n")
  257.    AdeptPrint(line, "       close\r\n")
  258.    AdeptPrint(line, "       site site-command\r\n")
  259.    AdeptPrint(line, "       dir pattern                        ls  pattern\r\n")
  260.    AdeptPrint(line, "       get remotefile [localfile]\r\n")
  261.    AdeptPrint(line, "       getb remotefile [localfile]        put localfile [remotefile]\r\n")
  262.    AdeptPrint(line, "       putb localfile [remotefile]        uput localfile [remotefile]\r\n")
  263.    AdeptPrint(line, "       uputb localfile [remotefile]\r\n")
  264.    AdeptPrint(line, "       rename oldname newname             delete filename\r\n")
  265.    AdeptPrint(line, "       append remotefile [localfile]      appendb remotefile [localfile]\r\n")
  266.    AdeptPrint(line, "       sys\r\n")
  267.    AdeptPrint(line, "       md directory                       cd directory\r\n")
  268.    AdeptPrint(line, "       rd directory\r\n")
  269.    AdeptPrint(line, "       pwd\r\n")
  270.    AdeptPrint(line, "       quit\r\n")
  271.  
  272. return
  273.