Thursday, September 27, 2007

VBScript to Retrieve a file from an URL and save it to the Hard Disk

'Script Start

URL = "http://sitename/filename.txt"
saveTo = "C:\filename.txt"

Set Obj1 = CreateObject("MSXML2.ServerObj1") "GET", URL, false
Set Obj2 = CreateObject("ADODB.Stream")
Obj2.Type = 1 'adTypeBinary
Obj2.Write Obj1.ResponseBody 'Give the XML string to the ADO Stream
Obj2.Position = 0 'Set the stream position to the start
Set FSO = Createobject("Scripting.FileSystemObject")
if fso.Fileexists(saveTo) then Fso.DeleteFile hdLocation
set FSO = Nothing
Obj2.SaveToFile saveTo
Set Obj2 = Nothing
Set Obj1 = Nothing

'Script End

Got from the site

How to execute a VBScript

No comments: