Re: VBS automatic HTTP download by Mark
Mark
Mon Jul 17 10:22:47 CDT 2006
Hello cfulton@nbisolutions.com,
> I am not sure which object to use in this task. I have tried the
> Scripting.FilsSystemObject, which does not work. After extensive
> searching I am unable to come up with a solution. Is there any way to
> do it with a VBScript?
You can use the xmlhttp object and the adodb.stream object (in case the remote
file is not a text file):
'---begin script
'GetRemoteBinaryFile.vbs
If WScript.Arguments.Count < 2 Then
WScript.Echo "Usage: GetRemoteBinary URL localname"
WScript.Quit(1)
End If
ImageFile = WScript.Arguments(1)
URL = WScript.Arguments(0)
Set xml = CreateObject("Microsoft.XMLHTTP")
xml.Open "GET", URL, False ', "", ""
xml.Send
set oStream = createobject("Adodb.Stream")
Const adTypeBinary = 1
Const adSaveCreateOverWrite = 2
Const adSaveCreateNotExist = 1
oStream.type = adTypeBinary
oStream.open
oStream.write xml.responseBody
' Do not overwrite an existing file
oStream.savetofile ImageFile, adSaveCreateNotExist
' Use this form to overwrite a file if it already exists
' oStream.savetofile DestFolder & ImageFile, adSaveCreateOverWrite
oStream.close
'---end scrip