Download from sourceforge or fosshub (qBittorrent)

Trying to download qBittorrent using powershell and all I got is:

Invoke-WebRequest -UserAgent 'Wget' -Uri https://sourceforge.net/projects/qbittorrent/files/latest/download -OutFile $ENV:temp\qBittorrent.exe

Problem is that’s super slow and I would like to use

(New-Object System.Net.WebClient).DownloadFile("INSERT-URL-HERE", "$ENV:temp\qBittorrent.exe")

But that’s not working because it’s Sourceforge…

These are the options to download from:

  1. Fosshub: qBittorrent download latest version
  2. Sourceforge: qBittorrent download | SourceForge.net

Edit:
Found an ugly solution:

Write-Host 'qBittorrent > Get latest' -ForegroundColor green -BackgroundColor black
$qBitReleases = Invoke-RestMethod 'https://github.com/qBittorrent/qBittorrent/releases.atom'
$qBitLatest = ($qBitReleases.title) -replace 'release-', '' | Select-Object -First 1
$qBitURL1 = 'https://deac-fra.dl.sourceforge.net/project/qbittorrent/qbittorrent-win32/qbittorrent-'
$qBitURL3 = '/qbittorrent_'
$qBitURL5 = '_x64_setup.exe?viasf=1'
$qBitFull = $qBitURL1 + $qBitLatest + $qBitURL3 + $qBitLatest + $qBitURL5
Write-Host 'qBittorrent > Download' -ForegroundColor green -BackgroundColor black
(New-Object System.Net.WebClient).DownloadFile("$qBitFull", "$ENV:temp\qBittorrent.exe")

That’s really ugly, but that’s working, I would like a more simple solution if someone got any.

Define ‘too slow’. What is your expectation? That downloaded in a couple seconds for me.

also…

this works just fine for me as well, and is a tad bit faster.

I would like to stop using

Invoke-WebRequest

and only use

(New-Object System.Net.WebClient).DownloadFile

Yes, it is faster, but I would like a better implementation, that’s just super ugly and it bothers me I can’t figure out how to make it better and simple.

You are contradicting yourself

you state you want to use

(New-Object System.Net.WebClient).DownloadFile("INSERT-URL-HERE", "$ENV:temp\qBittorrent.exe")

I tell you that it works and you say its too ugly? You failed to define what you consider too slow, then you state you only want to use (New-Object System.Net.WebClient).DownloadFile which i originally stated works… I’m super confused.

Do you want to use it or not want to use it? You are giving conflicting information.

$uri = 'https://sourceforge.net/projects/qbittorrent/files/latest/download'
(New-Object System.Net.WebClient).DownloadFile("$uri", "$ENV:temp\qBittorrent.exe")

works just fine. it takes 1 second for me to run on a home internet connection. Please clarify the ask.

If you want it to be more ‘simple’ write a wrapper function then call your wrapper function. but tbh, it’s pretty simple as is IMO, it’s a single method that takes two parameters.

Sorry about that, I’ll explain.

Invoke-WebRequest -UserAgent 'Wget' -Uri https://sourceforge.net/projects/qbittorrent/files/latest/download -OutFile $ENV:temp\qBittorrent.exe

Is slow on my machine, it takes 10 seconds to complete.

Write-Host 'qBittorrent > Get latest' -ForegroundColor green -BackgroundColor black
$qBitReleases = Invoke-RestMethod 'https://github.com/qBittorrent/qBittorrent/releases.atom'
$qBitLatest = ($qBitReleases.title) -replace 'release-', '' | Select-Object -First 1
$qBitURL1 = 'https://deac-fra.dl.sourceforge.net/project/qbittorrent/qbittorrent-win32/qbittorrent-'
$qBitURL3 = '/qbittorrent_'
$qBitURL5 = '_x64_setup.exe?viasf=1'
$qBitFull = $qBitURL1 + $qBitLatest + $qBitURL3 + $qBitLatest + $qBitURL5
Write-Host 'qBittorrent > Download' -ForegroundColor green -BackgroundColor black
(New-Object System.Net.WebClient).DownloadFile("$qBitFull", "$ENV:temp\qBittorrent.exe")

This takes only 3 seconds.

What I would like to do is create a powershell script that downloads the latest (non-beta) version of qBittorrent from sourceforge.
Which is another thing - I have to make sure it doesn’t catch the beta versions.

Just to be clear, we’re here to help with scripts, not write them for others. If you’re looking for someone to write you a script, you’ll want to engage with fiver or another paid service.

That said, this is mostly straight forward with a wrapper command, as previously mentioned.

function Get-BitTorrent {
    param (
        [string]$URI = 'https://sourceforge.net/projects/qbittorrent/files/latest/download',
        [string]$Location = "$env:temp\qbittorrent.exe"
    )
    (New-Object System.Net.WebClient).DownloadFile("$uri", "$Location") 
}

This is something I wrote in like 5-6 seconds. Then you can call Get-BitTorrent, and if you don’t provide any parameters, it’ll use the default parameters… Note that for each session you need to ‘load’ that function in your session, so it’s probably best to add it to your PS Profile. See: about Profiles - PowerShell | Microsoft Learn

If you don’t want to catch the beta versions, you’ll want to try to code that in. I don’t have any knowledge on how their releases are done, and whether they use different sources for different things.

Also, another option you can consider is using a package manager, such as chocolatey: Chocolatey Software | Chocolatey - The package manager for Windows

while the free version is community driven, they probably keep that up to date : Chocolatey Software | qBittorrent 4.6.4. It has the added benefit of installing it in the same step, and you can easily update.

I see you did not try it, because as I already said on my first post:

But that’s not working because it’s Sourceforge…

If there’s a possible way to pass it a user-agent the same way the first command uses, then it will work, which I haven’t found a way.

But… I don’t want to use chocolatey, I created a powershell script…
Also - I am familiar with chocolatey…

After some clarification via DMs, the issue was that while a file was downloading - it was not the actual installer.

This is because sourceforge requires Wget user agent for a ‘direct’ download that also attempts to grab the latest version.

function Get-BitTorrent {
    param (
        [string]$URI = 'https://sourceforge.net/projects/qbittorrent/files/latest/download',
        [string]$Location = "$env:temp\qbittorrent.exe"
    )
    $WebClient = New-Object System.Net.WebClient
    $WebClient.Headers.Add('user-agent','Wget')
    $WebClient.DownloadFile("$uri", "$Location")
}

Defining the user agent in the webclient appears to resolve the issue.

1 Like

I want to offer a different alternative. It does require two calls


function Get-BitTorrent {
    param (
        [string]$URI = 'https://sourceforge.net/projects/qbittorrent/files/latest/download',
        [string]$Location = "$env:temp\qbittorrent.exe"
    )
    $output = Invoke-WebRequest $URI -UseBasicParsing
    $link = $output.links.'data-release-url' | Select-Object -First 1
    Invoke-WebRequest $link -UseBasicParsing -OutFile $Location
}

It is faster than using Invoke-WebRequest with the wget agent, but you can also use the webclient instead.

function Get-BitTorrent {
    param (
        [string]$URI = 'https://sourceforge.net/projects/qbittorrent/files/latest/download',
        [string]$Location = "$env:temp\qbittorrent.exe"
    )
    $output = Invoke-WebRequest $URI -UseBasicParsing
    $link = $output.links.'data-release-url' | Select-Object -First 1
    $webclient = New-Object System.Net.WebClient
    $webclient.DownloadFile("$link", "$Location")
}
1 Like