Menu

VBscript download file from url

Updated: January 10, 2013

Ali Taheri

Simply:

  1. Create a text file then save it as example.vbs (with vbs extension).
  2. Copy and paste the code below:  
    Set args = WScript.Arguments
    
    '// you can get url via parameter like line below
    '//Url = args.Item(0)
    
     Url = "/mypdf.pdf"
    dim xHttp: Set xHttp = createobject("Microsoft.XMLHTTP")
    dim bStrm: Set bStrm = createobject("Adodb.Stream")
    xHttp.Open "GET", Url, False
    xHttp.Send
    
    with bStrm
        .type = 1 '//binary
        .open
        .write xHttp.responseBody
        .savetofile "d:\DownloladPdf.pdf", 2 '//overwrite
    end with
    
  3. Change the URL value. If you want to pass parameter you can just do it like this: example.vbs http://myurl.com/pdf2.pdf and uncomment Url = args.Item andremove Url = "/mypdf.pdf"

Tags

VBscript
comments powered by Disqus

© 2017 - Ali Sheikh Taheri