Downloading file from a web server with Command Line

Discussion in 'Scripting' started by Travis McGee, Mar 26, 2009.

  1. Travis McGee

    Travis McGee Guest

    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
     
    Travis McGee, Mar 26, 2009
    #1
    1. Advertisements

  2. 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/wgetwin-1_5_3_1-binary.zip -onul
     
    Pegasus [MVP], Mar 26, 2009
    #2
    1. Advertisements

  3. Travis McGee

    Travis McGee Guest

    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
     
    Travis McGee, Apr 1, 2009
    #3
  4. 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.
     
    Alex K. Angelopoulos, Apr 2, 2009
    #4
  5. Travis McGee

    Travis McGee Guest

    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


    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/
     
    Travis McGee, Apr 2, 2009
    #5
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.