Download with script


G

Guest

Guys,

Does anyone know how to download a file from a Http site
and save it to a local folder using either a batch file
or wsh script?

Thanks,
A.
 
Ad

Advertisements

G

Guest

I've posted this before in .scripting.vbscript ...

'------------------------8<---------------------------
' Source Alex K. Angelopoulos,
' modified by TGL Nov 2003
' From: http://groups.google.com/groups?
' selm=OxJBkB8xCHA.2120%40TK2MSFTNGP11

' Change this to point to a suitable location
Const sSavePath = ".\"

' Get URL for desired site
sPage = Trim(InputBox("Target Webpage (W/o http://)"))
if sPage = "" then Wscript.Quit(1)

' Keep full URL as file name, but replace slashes
sName = sSavePath & Replace(sPage, "/", "_")

' Get page
GetHTTP(sName, "http://" & sPage)

Wscript.Echo "Done"

Function GetHTTP(fName, sURL)
' Create an xmlhttp object:
With CreateObject("Microsoft.XMLHTTP")
.open "GET", sURL
.send
Do Until .ReadyState = 4 : wsh.sleep 50 : Loop
sData = .responseText
End With

' now save the page to a file.
CreateObject("Scripting.FileSystemObject")._
OpenTextFile(fName, 2, True).Write sData
End Function
'------------------------ End --------------------

It only copies the named document, not its links and imbedded images. Also, binary require a different write routine that uses the ADO.Stream object of v2.5+. You can do a search for a copy of DownBinFile for a similar routine for binaries. Others have posted similar. Try a groups.google search for more information
 
Ad

Advertisements


Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top