|This script uses the XMLHTTP
object to get a binary file, such as a picture, from
a remote host and save it to a file on the local
machine. Since WSH does not support binary
manipulation of files we use the ADODB.Stream object
to handle the saving of the data to a file.
In this example you must specify the
filename to save to in the string ImageFile and the
directory in which to store that file in the string
DestFolder (must exist and must end with a \
character). The remote location of the file is
stored in the string URL.
In real world usage you could
modify this simple sample to read URLs from a text
file, determine the filename from the URL and set
the destination path either once or for each URL.
Another usage would be to use the
SpecialFolders method to place a file on a user's
ImageFile = "back.gif"
DestFolder = "C:\"
URL = "http://www.paulsadowski.com/images1/back.gif"
Set xml = CreateObject("Microsoft.XMLHTTP")
xml.Open "GET", URL, False
set oStream = createobject("Adodb.Stream")
Const adTypeBinary = 1
Const adSaveCreateOverWrite = 2
Const adSaveCreateNotExist = 1
oStream.type = adTypeBinary
' Do not overwrite an existing file
oStream.savetofile DestFolder & ImageFile,
' Use this form to overwrite a file if it already
' oStream.savetofile DestFolder & ImageFile,
set oStream = nothing
Set xml = Nothing