ljb
Fri Jun 09 11:35:18 CDT 2006
"Alex" <samalex@gmail.com> wrote in message
news:1149868675.109312.174430@i39g2000cwa.googlegroups.com...
> Hello everyone,
>
> Okay probably a simple question, but I'm very green to VBS and I can't
> find this anywhere! In the Unix world I use wget to download just the
> source file for a given website, but I need to do this same thing in
> Windows and preferably with VBS.
>
> Basically what we're doing is downloading an xml file from a vendor's
> website then importing it into our MS SQL database via a VBS script
> (using QLXMLBulkLoad). I have this part working, but I now need to
> download the xml file from the web server. Ideally I'd like to put
> this download routine before the code that imports the XML content, but
> that's my delimma -- I dunno how to write it :)
>
> Thanks for any suggestions or pointers into the right direction. Take
> care --
>
> Alex
>
I found the follwoing on the web somewhere.
Option Explicit
Const cURL = "
http://source.jpg"
Const cOUT = "C:\destination.jpg"
WScript.Echo "Success? " & Fetch(cURL, cOUT)
Function Fetch(xURL, xOUT)
Const adSaveCreateOverWrite = 2
On Error Resume Next
Fetch = False
Err.Clear
Dim objXML, strXML
Set objXML = CreateObject("Microsoft.XMLHTTP")
' Set objXML = CreateObject("MSXML2.XMLHTTP.4.0")
With objXML
.Open "GET", xURL, False
.Send
strXML = .ResponseBody
End With
If Err.Number <> 0 Or objXML.Status <> 200 Then Exit Function
Set objXML = Nothing
Dim objADO
Set objADO = CreateObject("ADODB.Stream")
With objADO
.Open
.Type = 1
.Write strXML
.SaveToFile xOUT, adSaveCreateOverWrite
.Close
End With
Set objADO = Nothing
Fetch = Err.Number = 0
End Function