home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 18 REXX / 18-REXX.zip / rexxftp.zip / MINIFTP.CMD < prev    next >
OS/2 REXX Batch file  |  1993-08-29  |  8KB  |  251 lines

  1. /*------------------------------------------------------------------
  2.  * miniftp.cmd :
  3.  *------------------------------------------------------------------
  4.  * 03-16-93 originally by Patrick J. Mueller & Cliff Nadler
  5.  *------------------------------------------------------------------*/
  6.  
  7. trace off
  8.  
  9. /*------------------------------------------------------------------
  10.  * load functions, if needed
  11.  *------------------------------------------------------------------*/
  12. if RxFuncQuery("FtpLoadFuncs") then
  13.    do
  14.    rc = RxFuncAdd("FtpLoadFuncs","RxFtp","FtpLoadFuncs")
  15.    rc = FtpLoadFuncs()
  16.    end
  17.  
  18. if RxFuncQuery("SysLoadFuncs") then
  19.    do
  20.    rc = RxFuncAdd("SysLoadFuncs","RexxUtil","SysLoadFuncs")
  21.    rc = SysLoadFuncs()
  22.    end
  23.  
  24. /*------------------------------------------------------------------
  25.  * set up signal
  26.  *------------------------------------------------------------------*/
  27. signal on halt
  28.  
  29. parse value SysTextScreenSize() with rows cols
  30.  
  31. /*------------------------------------------------------------------
  32.  * get parameters
  33.  *------------------------------------------------------------------*/
  34. parse arg host user pass .
  35.  
  36. /*------------------------------------------------------------------
  37.  * set things
  38.  *------------------------------------------------------------------*/
  39. if (host <> "") & (user <> "") & (pass <> "") then
  40.    rc = FtpSetUser(host,user,pass)
  41. else
  42.    do
  43.    host = ""
  44.    user = ""
  45.    pass = ""
  46.    end
  47.  
  48. do while (cmd <> "QUIT")
  49.  
  50.    /*---------------------------------------------------------------
  51.     * print prompt
  52.     *---------------------------------------------------------------*/
  53.    say
  54.    say "Enter FTP command: (use ? for help)"
  55.  
  56.    /*---------------------------------------------------------------
  57.     * print status
  58.     *---------------------------------------------------------------*/
  59.    parse value SysCurPos(0,0) with row col
  60.  
  61.    do i = 1 to 4
  62.       call SysCurPos i-1, 0
  63.       say copies(" ",cols)
  64.    end
  65.  
  66.    if (host <> "") then
  67.       status = "connected to" user"@"host
  68.    else
  69.       status = "not connected to a host"
  70.  
  71.    junk = FtpPwd('dir')
  72.    if (junk <> 0) then
  73.       dir = "not specified"
  74.  
  75.    call SysCurPos 0,0
  76.  
  77.    say d2c(218) || copies(d2c(196),70)
  78.    say d2c(179) || " MiniFtp:" time() status
  79.    say d2c(179) || " directory:" dir
  80.    say d2c(192) || copies(d2c(196),70)
  81.  
  82.    call SysCurPos row, col
  83.  
  84.    /*---------------------------------------------------------------
  85.     * get command
  86.     *---------------------------------------------------------------*/
  87.    parse pull cmd cmdargs
  88.    parse var cmdargs file1 file2 rest
  89.  
  90.    if (file1 = "") then file1 = "*"
  91.    if (file2 = "") then file2 = file1
  92.  
  93.    /*------------------------------------------------------------------
  94.     * sanity check
  95.     *------------------------------------------------------------------*/
  96.    cmd = translate(cmd)
  97.  
  98.    if (host="") then
  99.       if (cmd <> "CONNECT") & (cmd <> "?") & (cmd <> "QUIT") then
  100.          do
  101.          say "You have not provided host, userid, and password information."
  102.          say "Use the CONNECT command to provide this information."
  103.          iterate
  104.          end
  105.  
  106.    /*---------------------------------------------------------------
  107.     * start timer for get/put
  108.     *---------------------------------------------------------------*/
  109.    if (cmd = "GET") | (cmd = "GETB") | (cmd = "PUT") | (cmd = "PUTB") then
  110.       call time "r"
  111.  
  112.    /*---------------------------------------------------------------
  113.     * run command
  114.     *---------------------------------------------------------------*/
  115.    err = 0
  116.    select
  117.       when (cmd = "QUIT")    then iterate
  118.       when (cmd = "GET")     then err = FtpGet(file1,file2,"ASCII")
  119.       when (cmd = "GETB")    then err = FtpGet(file1,file2,"BINARY")
  120.       when (cmd = "PUT")     then err = FtpPut(file1,file2,"ASCII")
  121.       when (cmd = "PUTB")    then err = FtpPut(file1,file2,"BINARY")
  122.       when (cmd = "UPUT")    then err = FtpPutUnique(file1,file2,"ASCII")
  123.       when (cmd = "UPUTB")   then err = FtpPutUnique(file1,file2,"BINARY")
  124.       when (cmd = "DELETE")  then err = FtpDelete(file1)
  125.       when (cmd = "RENAME")  then err = FtpRename(file1,file2)
  126.       when (cmd = "APPEND")  then err = FtpAppend(file1,file2,"ASCII")
  127.       when (cmd = "APPENDB") then err = FtpAppend(file1,file2,"BINARY")
  128.       when (cmd = "QUOTE")   then err = FtpQuote(cmdargs)
  129.       when (cmd = "SITE")    then err = FtpSite(cmdargs)
  130.       when (cmd = "CD")      then err = FtpChDir(file1)
  131.       when (cmd = "MD")      then err = FtpMkDir(file1)
  132.       when (cmd = "RD")      then err = FtpRmDir(file1)
  133.  
  134.       when (cmd = "DIR")     then err = FtpDir(file1,"stem.")
  135.       when (cmd = "LS")      then err = FtpLs(file1,"stem.")
  136.  
  137.       when (cmd = "CONNECT") then
  138.          do
  139.          parse var cmdargs host user pass
  140.          call FtpSetUser host, user, pass
  141.          end
  142.  
  143.       when (cmd = "CLOSE")   then
  144.          do
  145.          rc = FtpLogoff()
  146.          host = ""
  147.          user = ""
  148.          pass = ""
  149.          end
  150.  
  151.       when (cmd = "PWD")     then
  152.          do
  153.          junk = FtpPwd('curdir')
  154.          say "Current Remote Directory :" curdir
  155.          end
  156.  
  157.       when (cmd = "SYS")     then
  158.          do
  159.          junk = FtpSys('sys')
  160.          say "Returned from sys:" sys
  161.          end
  162.  
  163.       when (cmd = "?")       then call Usage
  164.  
  165.       otherwise
  166.          say "Invalid command. Use ? for help."
  167.    end
  168.  
  169.    /*---------------------------------------------------------------
  170.     * stop timer for get/put
  171.     *---------------------------------------------------------------*/
  172.    if (cmd = "GET") | (cmd = "GETB") | (cmd = "PUT") | (cmd = "PUTB") then
  173.       do
  174.       elapsed = strip(format(time("e"),10,2))
  175.  
  176.       if (cmd = "GET") | (cmd = "GETB") then
  177.          lfile = file2
  178.       else
  179.          lfile = file1
  180.  
  181.       bytes = stream(lfile,"C","QUERY SIZE")
  182.  
  183.       bps = strip(format(bytes/elapsed,10,2))
  184.       say "transmitted" bytes "bytes in" elapsed "seconds:" bps "bytes/second."
  185.       end
  186.  
  187.    /*------------------------------------------------------------------
  188.     * check error
  189.     *------------------------------------------------------------------*/
  190.    if (err <> 0) then
  191.       say "Error from FTP:" FTPERRNO
  192.  
  193.    /*------------------------------------------------------------------
  194.     * check for dir or ls
  195.     *------------------------------------------------------------------*/
  196.    if (cmd = "LS") | (cmd = "DIR") then
  197.       do i = 1 to stem.0
  198.          say stem.i
  199.       end
  200. end
  201.  
  202. /*------------------------------------------------------------------
  203.  * quit
  204.  *------------------------------------------------------------------*/
  205. done:
  206. rc = FtpSetUser("X","X","X")
  207. rc = FtpLogoff()
  208. exit
  209.  
  210. /*------------------------------------------------------------------
  211.  * break condition
  212.  *------------------------------------------------------------------*/
  213. halt:
  214.    say "Terminating ..."
  215.    signal done
  216.  
  217. /*------------------------------------------------------------------
  218.  * some simple help
  219.  *------------------------------------------------------------------*/
  220. Usage: procedure
  221.  
  222.    say "usage:"
  223.    say "   command ..."
  224.    say "is used to run ftp commands on a remote host"
  225.    say
  226.    say "where:"
  227.    say "   command can be one of:"
  228.    say "       connect host user password"
  229.    say "       close"
  230.    say "       site site-command"
  231.    say "       dir pattern"
  232.    say "       ls  pattern"
  233.    say "       get remotefile [localfile]"
  234.    say "       getb remotefile [localfile]"
  235.    say "       put localfile [remotefile]"
  236.    say "       putb localfile [remotefile]"
  237.    say "       uput localfile [remotefile]"
  238.    say "       uputb localfile [remotefile]"
  239.    say "       rename oldname newname"
  240.    say "       delete filename"
  241.    say "       append remotefile [localfile]"
  242.    say "       appendb remotefile [localfile]"
  243.    say "       sys"
  244.    say "       md directory"
  245.    say "       cd directory"
  246.    say "       rd directory"
  247.    say "       pwd"
  248.    say "       quit"
  249.  
  250.    return 0
  251.