0

I need a small script to download some programs. The URL's never change but the files do. Like when you download malwarebytes.

Example: "https://downloads.malwarebytes.com/file/mbam_current/"

The address doesnt change but the file name downloaded does. Every script i see, requires that you specify a file name. I dont want to do that, I want the script to pull the filename from the sites header which would include the version name of that file in that filename. I cant seem to find any way of doing this. Please help me o wonderful smart people.

It needs to work on any version of Windows 7 and up.

1
  • Please note that Super User is not a free script/code writing service. If you tell us what you have tried so far (include the scripts/code you are already using) and where you are stuck then we can try to help with specific problems. You should also read How do I ask a good question?.
    – DavidPostill
    Aug 29, 2016 at 8:58

1 Answer 1

1

Found something, this works !!!!!

import-module bitstransfer
$url="http://downloads.malwarebytes.com/file/mbam_current/"

Function Get-RedirectedUrl {

    Param (
        [Parameter(Mandatory=$true)]
        [String]$URL
    )

    $request = [System.Net.WebRequest]::Create($url)
    $request.AllowAutoRedirect=$false
    $response=$request.GetResponse()

    If ($response.StatusCode -eq "Found")
    {
        $response.GetResponseHeader("Location")
    }
}

$FileName = [System.IO.Path]::GetFileName((Get-RedirectedUrl "http://downloads.malwarebytes.com/file/mbam_current/"))

start-bitstransfer -source $url -Destination $FileName
1
  • 1
    That’s Powershell, in case anyone is wondering. It also probably won’t work for filenames sent in the Content-Disposition HTTP header.
    – Daniel B
    Aug 29, 2016 at 13:17

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .