Download files from webserver via vbs 
Author Message
 Download files from webserver via vbs

Hi,
I want to write a vbs to download a file from a http webserver and save
it to disk.
Regards
Wolfgang


Tue, 02 Aug 2005 22:37:47 GMT  
 Download files from webserver via vbs
This should work for a text source (but not for a binary source - the
Write will fail).

-----------8<-------------
' Source Alex K. Angelopoulos, modified by TGL 14 Feb 2003
' http://groups.google.com/groups?selm=OxJBkB8xCHA.2120%40TK2MSFTNGP11

' Change this to point to a suitable location
Const sSavePath = ".\"

' Get URL for desired site
sPage = Trim(InputBox("Target Webpage"))
if sPage = "" then Wscript.Quit(1)

' Keep full URL for storage file, but replace slashes
sName = sSavePath & Replace(sPage, "/", "_")

' Get page
sData = GetXml("http://" & sPage)

'now save the page to a file.
WriteFile sName, sData

Wscript.Echo "Done"

Function GetXml(sURL)
 ' Create an xmlhttp object:
 With CreateObject("Microsoft.XMLHTTP")
   .open "GET",sURL
   .send
   Do:wscript.sleep 50:Loop While .ReadyState<>4
   GetXml = .responseText
 End With
End Function

Sub WriteFile(FilePath, sData)
 'writes sData to FilePath
 CreateObject("Scripting.FileSystemObject")._
   OpenTextFile(FilePath, 2, True).Write sData
End Sub

-----------8<--------------

Tom Lavedas
===========

Quote:

> Hi,
> I want to write a vbs to download a file from a http webserver and save
> it to disk.
> Regards
> Wolfgang



Wed, 03 Aug 2005 04:49:02 GMT  
 Download files from webserver via vbs

Quote:

> Hi,
> I want to write a vbs to download a file from a http webserver and save
> it to disk.
> Regards
> Wolfgang

Hi, Wolfgang

Here is a Michael Harris script which I may have modified that uses the Microsoft.XMLHTTP and ADODB.Stream objects, and which has
never failed for me for binary, text, or files with various encodings, and allows accessing password-protected files too.
-Paul Randall

'Here's the ADODB.Stream version...
'Requires ADO 2.5 or higher...
'--Begin user variables--
sSource = "http://www.microsoft.com/homepage/gif/artTech.gif"
sDest = "test.gif"
sUser = ""
sPassword = ""
'---End user variables---
wsh.echo  sSource & vbNewLine & sDest
set oHTTP = CreateObject("Microsoft.XMLHTTP")
oHTTP.open "GET", sSource, False, sUser, sPassword
oHTTP.send
const adTypeBinary = 1
const adSaveCreateOverwrite = 2
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
WScript.Echo "Done!"



Wed, 03 Aug 2005 05:27:32 GMT  
 Download files from webserver via vbs
ASPTear might help, it is free and very straight forward to use:

http://www.alphasierrapapa.com/IisDev/Components/AspTear/

Ed Callahan


Quote:
> Hi,
> I want to write a vbs to download a file from a http webserver and save
> it to disk.
> Regards
> Wolfgang



Thu, 04 Aug 2005 01:01:18 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Howto: download a file from HTTP-Webserver

2. Help uploading a binary file from vb to Webserver via HTTP

3. Scripting IE to download a file via http

4. Downloading files via IE ?

5. Download some Files via FTP

6. Downloading files via VBScript..."foolproof"?

7. File download via IE using WSH

8. Downloading files via HTTP

9. Download File via FTP/HTTP and other questions

10. How to download a file via scripting?

11. Scripting IE to download a file via http

12. Uploading a textfile to webserver via VB5 + Winsock (No 3rd Party OCXs)

 

 
Powered by phpBB® Forum Software