Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Stream object: http download problem

Status
Not open for further replies.

mkal

Programmer
Jun 24, 2003
223
US
I have been trying to download a text file from a web page by using the script below but get the following error message from WSH, "Script: c\ic.vbs, Line: 15, Char: 1, Error: 0x800C0005, Code: 800C0005, Source: (null)

'GetRemoteTextFile.vbs
'WScript.Echo WScript.Version '(5.6 is my version)

Const adTypeText = 2
Const adSaveCreateOverWrite = 2
Const adSaveCreateNotExist = 1
Const adModeReadWrite = 3

ImageFile = "products.txt"
DestFolder = "C:\"
URL = "
Set xml = CreateObject("Microsoft.XMLHTTP")
xml.Open "GET", URL, False
xml.Send

set oStream = CreateObject("ADODB.Stream")

oStream.Mode = adModeReadWrite
oStream.type = adTypeText
oStream.open
contents = xml.responseBody

' Do not overwrite an existing file
'oStream.savetofile DestFolder & ImageFile, adSaveCreateNotExist

' Use this form to overwrite a file if it already exists
oStream.write(contents)
oStream.savetofile DestFolder & ImageFile, adSaveCreateOverWrite

oStream.close

set oStream = nothing
Set xml = Nothing

I am trying to run this from an ActiveXscript within a Data Transformation package for SQL 2000. Wasn't sure where to post but started here.

Any info is greatly appreciated!
 
You may take a look at the last post (courtesy of Dilettante) here: thread329-532735

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
Hello mkal,

error 800c0007 = The server or proxy was not found. To have graceful exit in this or other circumstances use err trapping.
Code:
'lines above
on error resume next
Set xml = CreateObject("Microsoft.XMLHTTP")
xml.Open "GET", URL, False
xml.Send
if err.number<>0 then
    wscript.echo hex(err.number)
    'whatever other actions - radical quit is just one option
    wscript.quit(1)
end if
err.clear
on error goto 0
Even if you get into contact with the link, the server may not be ready. So any further action also depends on the return of xml.status. If xml.status=200 then your save action should go ahead, else (including the infamous 500) it should not. This is another bit you have to add.

regards - tsuji
 
Thanks to you both, for the help. It appears however, that the fault was mine and not the code, I had a bad URL. Once that was fixed everything worked well.

I like the err handler routine and will add that into my script as well. Also, thanks for the reminder about FAQ.

Best Regards,
Mike
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top