## Grab an image from a website
#
# Adapted from a script by Michael Harris
# Microsoft.MVP.Scripting
{
-start
-stop
GetImage("bracka.gif")
Print("Done! at %c%")
}
Function GetImage(args)
sSrcUrl = "http://129.13.102.67/" & "wz/pics/"
sImageFile = args
sContentTypeExpected = "image/gif"
sDestFolder = "c:\temp\"
set oHTTP = CreateObject("msxml2.XMLHTTP")
oHTTP.open "GET", sSrcUrl & sImageFile, False
oHTTP.send
if oHTTP.status <> 200 then
msgbox "unexpected status = " & oHTTP.status & vbcrlf & oHTTP.statusText
Exit Function
end if
sContentTypeReturned = oHTTP.getResponseHeader("content-type")
if sContentTypeReturned <> sContentTypeExpected then
msgbox "unexpected content-type = " & sContentTypeReturned & vbcrlf & "expected = " & sContentTypeExpected
oHTTP = Nothing
Exit Function
end if
set oStream = createobject("adodb.stream")
Const adTypeBinary = 1
Const adSaveCreateOverWrite = 2
oStream.type = adTypeBinary
oStream.open
oStream.write oHTTP.responseBody
oStream.savetofile sDestFolder & sImageFile, adSaveCreateOverWrite
oStream = Nothing
oHTTP = Nothing
End Function