[Solved] Download a file using script

Discussion in 'Scripting' started by BJ0RN, Jan 25, 2017.

  1. BJ0RN

    BJ0RN MDL HTTP-uploader

    Dec 6, 2013
    334
    21,791
    10
    Hello MDL'ers :hug2:

    Got something I need help with, I want to download the "default" file from https://download.geogebra.org/package/win-autoupdate
    The url will start the download automatically when opened in a browser.
    I want this done in a script so that when run it will download the newest file (well the one it downloads when opened in browser), save it to set location and renamed to xxxxx.exe

    Anyone got tips/tricks?


    Best, Bjørn
     
  2. BJ0RN

    BJ0RN MDL HTTP-uploader

    Dec 6, 2013
    334
    21,791
    10
    #2 BJ0RN, Jan 25, 2017
    Last edited: Jan 25, 2017
    (OP)
    Solved by myself (not really, co-worker helped me) :D
    wget *link* -OutFile name.exe
     
  3. bear_aussie

    bear_aussie MDL Senior Member

    Jun 8, 2015
    271
    292
    10
    #3 bear_aussie, Jan 28, 2017
    Last edited by a moderator: Apr 20, 2017
    or the True Scripting Way (vbscript) - saw this a few years ago went straight into my "coolscripts" folder :D
    Code:
    Function HTTPDownload(AURL, ADest)
    Dim Buffer
    Dim ADODB
    
    ' Assume failure
    HTTPDownload = FALSE
    
    ' Create the ADM stream and HTTP request.
    Set ADODB = CreateObject("ADODB.Stream")
    Set Buffer = CreateObject("MSXML2.XMLHTTP")
    Buffer.Open "GET", AURL, FALSE
    On Error Resume Next
    Buffer.Send EMPTY
    On Error GoTo 0
    
    ' Check that the request is completed (ReadyState is 4). If it isn't, warn.
    If Buffer.ReadyState = 4 Then
    WScript.Echo "Status:", Buffer.Status, AURL
    Else
    WScript.Echo "Ready State <> 4: ", AURL
    End If
    
    ' If the status is 200 (found), save the body to the destination. Easy.
    If Buffer.Status = 200 Then
    If Not (ADODB.State = 0) Then _
    ADODB.Close
    ADODB.Type = 1 ' 1 is binary, 2 is text)
    ADODB.Mode = 3 ' 1 is read, 2 is write - ORed.
    ADODB.Open
    ADODB.Write Buffer.ResponseBody
    ADODB.SaveToFile ADest, 2
    ADODB.Close
    
    HTTPDownload = TRUE
    End If
    End Function
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...