omegastripes

simple_host_file_upload_octet_stream.vbs

Jan 7th, 2016
227
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. strFilePath = "C:\Users\DELL\Desktop\gt.png"
  2. UploadFile strFilePath, strUplStatus, strUplResponse
  3. MsgBox strUplStatus & vbCrLf & strUplResponse
  4.  
  5. Sub UploadFile(strPath, strStatus, strResponse)
  6.    
  7.     Dim strFile, strBoundary, bytData, bytPayLoad
  8.    
  9.     On Error Resume Next
  10.     With CreateObject("Scripting.FileSystemObject")
  11.         If .FileExists(strPath) Then
  12.             strFile = .GetFileName(strPath)
  13.         Else
  14.             strStatus = "File not found"
  15.             Exit Sub
  16.         End If
  17.     End With
  18.     With CreateObject("ADODB.Stream")
  19.         .Type = 1
  20.         .Mode = 3
  21.         .Open
  22.         .LoadFromFile strPath
  23.         If Err.Number <> 0 Then
  24.             strStatus = Err.Description & " (" & Err.Number & ")"
  25.             Exit Sub
  26.         End If
  27.         bytData = .Read
  28.     End With
  29.     strBoundary = String(6, "-") & Replace(Mid(CreateObject("Scriptlet.TypeLib").Guid, 2, 36), "-", "")
  30.     With CreateObject("ADODB.Stream")
  31.         .Mode = 3
  32.         .Charset = "Windows-1251"
  33.         .Open
  34.         .Type = 2
  35.         .WriteText "--" & strBoundary & vbCrLf
  36.         .WriteText "Content-Disposition: form-data; name=""upload_file""; filename=""" & strFile & """" & vbCrLf
  37.         .WriteText "Content-Type: octet/stream" & vbCrLf & vbCrLf
  38.         .Position = 0
  39.         .Type = 1
  40.         .Position = .Size
  41.         .Write bytData
  42.         .Position = 0
  43.         .Type = 2
  44.         .Position = .Size
  45.         .WriteText vbCrLf & "--" & strBoundary & "--"
  46.         .Position = 0
  47.         .Type = 1
  48.         bytPayLoad = .Read
  49.     End With
  50.     With CreateObject("MSXML2.ServerXMLHTTP")
  51.         .SetTimeouts 0, 60000, 300000, 300000
  52.         .Open "POST", "http://tessstt.esy.es/upload.php", False
  53.         .SetRequestHeader "Content-type", "multipart/form-data; boundary=" & strBoundary
  54.         .Send bytPayLoad
  55.         If Err.Number <> 0 Then
  56.             strStatus = Err.Description & " (" & Err.Number & ")"
  57.         Else
  58.             strStatus = .StatusText & " (" & .Status & ")"
  59.         End If
  60.         If .Status = "200" Then strResponse = .ResponseText
  61.     End With
  62.    
  63. End Sub
Add Comment
Please, Sign In to add comment