home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 35 Internet / 35-Internet.zip / srev13h.zip / DOPUT.CMD < prev    next >
OS/2 REXX Batch file  |  1996-07-13  |  3KB  |  85 lines

  1. /* DOPUT -- send a file to a HTTP server, using the PUT verb */
  2. /* Call as:  DOPUT serveraddress url_to_use filename                   */
  3. /* ------------------------------------------------------------------- */
  4. /* This program requires that the RxSock.DLL be in your LIBPATH (it is */
  5. /* usually in your \TCPIP\DLL directory.  It was shipped with the      */
  6. /* August 1994 CSD for the TCP/IP base (UN64092).                      */
  7.  
  8. call load /* load functions if necessary */
  9.  
  10. say " Program to transfer files to HTTP server using the PUT verb "
  11.  
  12. parse arg server  use_url afile
  13.  
  14. if server="" then do 
  15.    say " Reminder: the HTTP server must support the PUT verb "
  16.    say "  (you may also require special access privileges) "
  17.  
  18.     say " Please enter server address: "
  19.     parse pull server
  20. end  /* Do */
  21. if use_url="" then  do
  22.   say " Please enter url to use (on " server "): "
  23.   parse pull use_url
  24. end
  25. if afile="" then do
  26.      say " Please enter the file you want to transfer: "
  27.      parse pull afile
  28.      foo=stream(afile,'c','query exists')
  29.      if foo="" then  do
  30.          say " Error: file does not exist "
  31.         exit
  32.      end
  33. end
  34.  
  35. crlf    ='0d0a'x                        /* constants */
  36. family  ='AF_INET'
  37. httpport=80
  38.  
  39. rc=sockgethostbyname(server, "serv.0")  /* get dotaddress of server */
  40. if rc=0 then do; say 'Unable to resolve "'server'"'; exit; end
  41. dotserver=serv.0addr                    /* .. */
  42.  
  43. gosaddr.0family=family                  /* set up address */
  44. gosaddr.0port  =httpport
  45. gosaddr.0addr  =dotserver
  46.  
  47. gosock = SockSocket(family, "SOCK_STREAM", "IPPROTO_TCP")
  48.  
  49.  
  50. message='PUT ' use_url ' HTTP/1.0'crlf
  51. message=message||'Content-type:application/x-www-form-urlencoded'||crlf
  52.  
  53. lt1=chars(afile)
  54. t1=charin(afile,1,lt1)
  55. message=message||'Content-length:'||lt1||crlf
  56.  
  57. message=message||crlf||t1
  58. say " Starting transfer of  " lt1 " byte file  ... "
  59.  
  60. got=''
  61. rc = SockConnect(gosock,"gosaddr.0")
  62. if rc<0 then do; say 'Unable to connect to "'server'"'; exit; end
  63. rc = SockSend(gosock, message)
  64. say " bytes transfered = " rc " .. waiting for reply .... "
  65.  
  66. /* Now wait for the response */
  67. do r=1 by 1
  68.   rc = SockRecv(gosock, "response", 1000)
  69.   got=got||response
  70.   /* say '>'rc'/>' response */
  71.   if rc<=0 then leave
  72.   end r
  73. rc = SockClose(gosock)
  74.  
  75. say 'Got' length(got) 'bytes of response:'
  76. say  got
  77. exit
  78.  
  79. /* --- Load the function library, if necessary --- */
  80. load:
  81. if \RxFuncQuery("SockLoadFuncs") then return      /* already there */
  82. call RxFuncAdd "SockLoadFuncs","rxSock","SockLoadFuncs"
  83. call SockLoadFuncs
  84. return
  85.