home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 35 Internet / 35-Internet.zip / bircv02b.zip / dcc_get.cmd < prev    next >
OS/2 REXX Batch file  |  1999-03-12  |  2KB  |  116 lines

  1. /* BiRC: DCC get.... */
  2. /* LONG IP: (FirstPart*16777216) + (SecondPart * 65536) + (ThirdPart * 256) + (FourthPart) */
  3.  
  4. call RxFuncAdd 'SysLoadFuncs','RexxUtil','SysLoadFuncs'
  5. call SysLoadFuncs
  6. call RxFuncAdd 'SockLoadFuncs','RxSock','SockLoadFuncs'
  7.  
  8. parse arg nick file longip port filesize
  9.  
  10. LastPart = (LongIP // 256)%1
  11. ThirdPart = (LongIP / 256 // 256)%1
  12. SecondPart = (LongIP / 65536 // 256)%1
  13. FirstPart = (LongIP / 16777216 // 256)%1
  14. ip=firstpart'.'secondpart'.'thirdpart'.'lastpart
  15.  
  16. call SockLoadFuncs 'q'
  17.  
  18. '@echo off'
  19.  
  20. say 'DCC: Responding to request from' nick' ['ip']'
  21.  
  22. socket  = SockSocket("AF_INET","SOCK_STREAM",0)
  23. if (socket = -1) then
  24.    do
  25.    say "Error on SockSocket:" errno
  26.    exit
  27.    end
  28.  
  29. signal on halt
  30.  
  31. server.!family = "AF_INET"
  32. server.!port   = port
  33. server.!addr   = ip
  34.  
  35. rc = SockConnect(socket,"server.!")
  36.  
  37. if (rc = -1) then
  38.    do
  39.    say "Error on SockConnect:" errno
  40.    exit
  41.    end
  42.  
  43. say 'Connected!'
  44.  
  45. 'if exist 'file' del 'file
  46.  
  47. say 'Size of file: 'filesize
  48.  
  49. bytesreceived=0
  50.  
  51. finished='false'
  52.  
  53. call stream file, 'c', 'open write'
  54.  
  55. do until (finished='true')
  56.  
  57. rc = SockRecv(socket, "data",512)
  58. if (rc = -1) then
  59.    do
  60.    say "Error on SockRecv:" errno
  61.    exit
  62.    end
  63.  
  64. call charout file, data
  65.  
  66. bytesreceived=bytesreceived+length(data)
  67.  
  68. call charout ,bytesreceived' bytes received.'||d2c(13)
  69.  
  70. prelim=''
  71.  
  72. /* if length(d2c(bytesreceived)<4) then
  73.    do i=1 to length(bytesreceived)
  74.    prelim=prelim||'0'
  75.    end */
  76.  
  77. /* call SockSend socket, prelim||d2c(bytesreceived) */
  78.  
  79. byte4 = (bytesreceived // 256)%1
  80. byte3 = (bytesreceived / 256 // 256)%1
  81. byte2 = (bytesreceived / 65536 // 256)%1
  82. byte1 = (bytesreceived / 16777216 // 256)%1
  83.  
  84. call SockSend socket, d2c(byte1)||d2c(byte2)||d2c(byte3)||d2c(byte4)
  85.  
  86. if (bytesreceived=filesize/* || length(data)=0*/) then finished='true'
  87.  
  88. end /* Main do loop */
  89.  
  90. call stream file, 'c', 'close'
  91.  
  92. halt()
  93.  
  94. exit
  95.  
  96. /* Exit procedure */
  97.  
  98. halt:
  99.  
  100. rc = SockSoClose(socket)
  101. if (rc = -1) then
  102.    do
  103.    say "Error on SockSoClose:" errno
  104.    exit
  105.    end
  106.  
  107. exit
  108.  
  109. /*
  110. byte4 = (bytesreceived // 256)%1
  111. byte3 = (bytesreceived / 256 // 256)%1
  112. byte2 = (bytesreceived / 65536 // 256)%1
  113. byte1 = (bytesreceived / 16777216 // 256)%1
  114. */
  115.  
  116.