XMLHTTP download has 404 status



I'm trying to use VBScript to download a zip file from a course
management system. Here's the part that does the downloading:

'======================================
' function to download a file from URL sSource to file sDest

function Download(sSource,sDest)
Dim oHttp, Stream, Start, fso, OldName
Const adModeReadWrite = 0, adTypeBinary = 1, adSaveCreateOverwrite = 2
Set fso = CreateObject("Scripting.FileSystemObject")

' If there's already something by that name, rename it with .old
if fso.fileexists(Sdest) then
OldName = Sdest & ".old"
' If there's already a .old, delete it
if fso.fileexists(OldName) then
fso.DeleteFile (OldName)
fso.MoveFile Sdest ,OldName
end if
end if

Set oHttp = CreateObject("MSXML2.XMLHTTP")
oHttp.Open "GET", sSource, False
oHttp.send

' If we can't have it perfect, we need to know.
if oHTTP.status <> 200 then
msgbox "unexpected status: " _
& oHTTP.status & " " & oHTTP.statusText _
& " for " & vbcrlf _
& sSource
wscript.quit
end if

' Ok, write the file
Set Stream = CreateObject("adodb.Stream")
Stream.Type = adTypeBinary
Stream.Mode = adModeReadWrite
Stream.Open
Stream.write oHttp.responseBody
Stream.SaveToFile sDest, adSaveCreateOverwrite
Stream.Close
Set oHttp = Nothing
Set Stream = Nothing
end function
'======================================

I call this function with a given URL and destination. It quits with a
status of 404 File not Found. If I pass the same url to
internetexplorer.navigate, I get a nice Save As dialog which
successfully retrieves the file. The environment from which I am
retrieving this zip file seems to be looking for things like a cookie
or referrer values in the header.

Is there a way I can automate the Save As window?
Is there some other way to save the file using Internet Explorer
instead of MSXML2.XMLHTTP?

.



Relevant Pages

  • Re: XMLHTTP download has 404 status
    ... Here's the part that does the downloading: ... Dim oHttp, Stream, Start, fso, OldName ... Set oHttp = CreateObject ... Set Stream = CreateObject ...
    (microsoft.public.scripting.vbscript)
  • Re: Recommended Approach
    ... Dan heres a vbscript that download a zip file from web, ... set oHTTP = WScript.CreateObject ... oStream.savetofile sDest, adSaveCreateOverWrite ...
    (microsoft.public.sqlserver.security)