Windows Vista Tips

Windows Vista Tips > Newsgroups > Windows Server > Scripting > Downloading file from a web server with Command Line

Reply
Thread Tools Display Modes

Downloading file from a web server with Command Line

 
 
Travis McGee
Guest
Posts: n/a

 
      03-26-2009
I remember Don Box showed something like this, I think.....web browsing from
command line without the browser.

I have vb scripts that are downloading files by Shelling out script to bring
files from an FTP server.

Now, there are some files sitting on a web site (with Directrory Browsing
enabled)
How can I download and save those data files on to hard disk, by either
using Command Line or I can use Browser Object from vbScript

I know, Browser Object does not have any methods for saving files due to
security reasons.

Can anybody find a solution to this outside of .NET coding. It has to be
VBScript based.

Thanks


 
Reply With Quote
 
 
 
 
Pegasus [MVP]
Guest
Posts: n/a

 
      03-26-2009

"Travis McGee" <> wrote in message
news:...
>I remember Don Box showed something like this, I think.....web browsing
>from command line without the browser.
>
> I have vb scripts that are downloading files by Shelling out script to
> bring files from an FTP server.
>
> Now, there are some files sitting on a web site (with Directrory Browsing
> enabled)
> How can I download and save those data files on to hard disk, by either
> using Command Line or I can use Browser Object from vbScript
>
> I know, Browser Object does not have any methods for saving files due to
> security reasons.
>
> Can anybody find a solution to this outside of .NET coding. It has to be
> VBScript based.
>
> Thanks


You could invoke wget.exe (http://www.interlog.com/~tcharron/wgetwin.html)
from within your VB Script, using the Run or Exec method. Here is the
command line for downloading the wget zip package:
wget.exe http://www.interlog.com/~tcharron/wg...3_1-binary.zip -onul


 
Reply With Quote
 
Travis McGee
Guest
Posts: n/a

 
      04-01-2009
To Tom Lavedas:

Thank you Tom for the help. I knew that it was possible....and yours is the
ideal solution that I am looking for.

The problem is that it is failing in the saveToFile method.
Obviously, the path does exist and don't expect permission/security is the
cause of the failure.
I did not try a binary file, but I am sure that it will fail the same way.

This is an ascii/htmls file.....so oXml.ResponseText property does have
the text of the page.
Also, I can see the responseBody stream in a char array.

I am sure it is the Flags problem. I can take it from here with more
research and exprerimentation...... but if you don't have anything else more
productive to do, can you figure it out by just looking at the flags. Err:
3004 Error: Write to file failed.

Thanks a Billion

Travis McGee
Boston


Sub bringFilesFromWebSite()
sFilePath = "c:\data"
sURL = "http://www.pharmac.govt.nz/schedule/archive/README.html"
Set oXml = CreateObject("Microsoft.XMLHTTP")
oXml.Open "GET", sURL, False
oXml.sEnd
With CreateObject("ADODB.Stream")
.Type = 1 'binary
.Mode = 3 'adModeReadWrite
.Open
On Error Resume Next
Do
.write oXml.responseBody
Loop Until Err = 0
On Error GoTo 0
.savetofile sFilePath, 2 'adSaveCreateOverwrite
End With
End Sub


 
Reply With Quote
 
Alex K. Angelopoulos
Guest
Posts: n/a

 
      04-02-2009
Actually, the problem is likely that you're using the name of a pre-existing
folder as the file path. Change sFilePath from
c:\data
to
c:\data\README.html
or whatever you want as the file name.

"Travis McGee" <> wrote in message
news:...
> To Tom Lavedas:
>
> Thank you Tom for the help. I knew that it was possible....and yours is
> the ideal solution that I am looking for.
>
> The problem is that it is failing in the saveToFile method.
> Obviously, the path does exist and don't expect permission/security is the
> cause of the failure.
> I did not try a binary file, but I am sure that it will fail the same way.
>
> This is an ascii/htmls file.....so oXml.ResponseText property does have
> the text of the page.
> Also, I can see the responseBody stream in a char array.
>
> I am sure it is the Flags problem. I can take it from here with more
> research and exprerimentation...... but if you don't have anything else
> more productive to do, can you figure it out by just looking at the flags.
> Err: 3004 Error: Write to file failed.
>
> Thanks a Billion
>
> Travis McGee
> Boston
>
>
> Sub bringFilesFromWebSite()
> sFilePath = "c:\data"
> sURL = "http://www.pharmac.govt.nz/schedule/archive/README.html"
> Set oXml = CreateObject("Microsoft.XMLHTTP")
> oXml.Open "GET", sURL, False
> oXml.sEnd
> With CreateObject("ADODB.Stream")
> .Type = 1 'binary
> .Mode = 3 'adModeReadWrite
> .Open
> On Error Resume Next
> Do
> .write oXml.responseBody
> Loop Until Err = 0
> On Error GoTo 0
> .savetofile sFilePath, 2 'adSaveCreateOverwrite
> End With
> End Sub
>
>

 
Reply With Quote
 
Travis McGee
Guest
Posts: n/a

 
      04-02-2009
Yes, of course. Stupid Me. It needs the SaveAs file name on the local
directory.
So, case closed; Class dismissed.
Alex & Levadas: You guys can take the rest of the day off.
Kind Regards


"T Lavedas" <> wrote in message
news:eee56a9d-7f20-4e7f-bb73-...
On Apr 2, 1:10 am, "Alex K. Angelopoulos" <aka(at)mvps.org> wrote:
> Actually, the problem is likely that you're using the name of a
> pre-existing
> folder as the file path. Change sFilePath from
> c:\data
> to
> c:\data\README.html
> or whatever you want as the file name.
>
> "Travis McGee" <travisGatesMc...@hotmail.com> wrote in message
>
> news:...
>
> > To Tom Lavedas:

>
> > Thank you Tom for the help. I knew that it was possible....and yours is
> > the ideal solution that I am looking for.

>
> > The problem is that it is failing in the saveToFile method.
> > Obviously, the path does exist and don't expect permission/security is
> > the
> > cause of the failure.
> > I did not try a binary file, but I am sure that it will fail the same
> > way.

>
> > This is an ascii/htmls file.....so oXml.ResponseText property does have
> > the text of the page.
> > Also, I can see the responseBody stream in a char array.

>
> > I am sure it is the Flags problem. I can take it from here with more
> > research and exprerimentation...... but if you don't have anything else
> > more productive to do, can you figure it out by just looking at the
> > flags.
> > Err: 3004 Error: Write to file failed.

>
> > Thanks a Billion

>
> > Travis McGee
> > Boston
> > travisGatesMc...@hotmail.com

>
> > Sub bringFilesFromWebSite()
> > sFilePath = "c:\data"
> > sURL = "http://www.pharmac.govt.nz/schedule/archive/README.html"
> > Set oXml = CreateObject("Microsoft.XMLHTTP")
> > oXml.Open "GET", sURL, False
> > oXml.sEnd
> > With CreateObject("ADODB.Stream")
> > .Type = 1 'binary
> > .Mode = 3 'adModeReadWrite
> > .Open
> > On Error Resume Next
> > Do
> > .write oXml.responseBody
> > Loop Until Err = 0
> > On Error GoTo 0
> > .savetofile sFilePath, 2 'adSaveCreateOverwrite
> > End With
> > End Sub


Yes, I see that I used an inappropriate name for the variable.
Instead of sFilePath, I should have used sFileSpec (or added a comment
that indicated it needed to be a fully qualified file specification -
that is path and name.ext).

Tom Lavedas
***********
http://there.is.no.more/tglbatch/


 
Reply With Quote
 
 
 
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
command line file compression yawnmoth Windows Vista General Discussion 3 07-30-2007 07:39 PM
How to get complete file attributes list on command line? Roof Fiddler Windows Vista File Management 1 09-28-2006 06:31 AM
mail or copy a file from command line.. Eric bouxirot Windows Small Business Server 1 06-20-2006 01:01 PM
COmmand Line for finding File Version Information Chris Windows Server 2 03-09-2006 12:18 PM
How to retrieve file from VSS via program or command line. prof chen Windows Small Business Server 1 03-03-2005 08:24 AM



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59