Tuesday, April 5, 2005

Copying files from internet using VBS

I got a question on how to do this from my fellow worker Robert and thought I should put the answer here.
One way is using the XMLHTTP object combined with adodb.stream like this using VBScript:

' Requirements: ADO 2.5+ and IE 5+
sSourceUrl = "http://www.jtbworld.com/images/"
sDestFolder = "c:\temp\"
sImageFile = "jtbworld.gif"
Set oXMLHTTP = WScript.CreateObject("Microsoft.XMLHTTP")
oXMLHTTP.open "GET", sSourceUrl & sImageFile, False
oXMLHTTP.send
Set oStream = CreateObject("adodb.stream")
Const adTypeBinary = 1
Const adSaveCreateOverWrite = 2
oStream.Type = adTypeBinary
oStream.open
oStream.write oXMLHTTP.responseBody
oStream.SaveToFile sDestFolder & sImageFile, adSaveCreateOverWrite
Set oStream = Nothing
Set oXMLHTTP = Nothingx


Some of the latest blog posts

Subscribe to RSS headline updates from:
Powered by FeedBurner