'call with 2 parameters, the name of the server to fetch from and the name of the file to fetch
dim xHttp 'create http getter object pointer
set xHttp = createobject("Microsoft.XMLHTTP") 'create http getter object
dim bStrm 'create bitstream object pointer
set bStrm = createobject("Adodb.Stream") 'create bitstream object
dim targetServer 'holds the name of the server
targetServer = WScript.Arguments(0) 'take the first argument and put it into targetServer
dim targetURL 'holds the final url
targetURL = "http://" & targetServer & "/" & WScript.Arguments(1)
WScript.echo "Fetching " & WScript.Arguments(1) &" from " & targetURL & "..."
xHttp.Open "GET", targetURL & "?" & Rnd,False 'setup the get instruction
xHttp.Send 'get the file
WScript.echo "HTTP Response Code: " & xHttp.status
if xHttp.status>=400 and xHttp.status <=599 then
WScript.echo targetURL & " was not found on " & targetServer
WScript.Quit 1
Else
'get the current working directory
dim fso
dim curDir
set fso = CreateObject("Scripting.FileSystemObject")
curDir = fso.GetAbsolutePathName(".")
set fso = nothing
'done getting the current working directory
with bStrm
.type = 1 'set to binary mode
.open 'open the stream
.write xHttp.responseBody 'write the response of the http get to the stream
WScript.echo "Saving to " & curDir & "\" & WScript.Arguments(1) & targetServer
.savetofile curDir & "\" & WScript.Arguments(1) & targetServer, 2 'save the stream to a file, overwriting
end with
End If