Fix WinSCP download by spoofing a curl-like User-Agent

Root cause found: winscp.net's download URL serves a human "please wait"
landing page (18KB HTML) instead of redirecting to the real file, unless
the User-Agent contains a known download-tool signature like curl or Wget.
PowerShell's own default UA always gets the landing page - confirmed by
reproducing locally with various UAs against the live URL. Not antivirus,
not TLS, not a network block; overriding -UserAgent to a curl string on
Invoke-WebRequest resolves it.
This commit is contained in:
2026-07-05 19:34:14 -05:00
parent 0805011ac6
commit a92dc68cb9
+5 -2
View File
@@ -11,7 +11,10 @@ if (Test-Path $zip) { Remove-Item $zip -Force }
Write-Host "Downloading WinSCP from $url ..." Write-Host "Downloading WinSCP from $url ..."
try { try {
Invoke-WebRequest -Uri $url -OutFile $zip -UseBasicParsing # winscp.net serves a human "please wait" landing page instead of the real
# file unless the User-Agent looks like a known download tool (curl/wget) -
# PowerShell's own default UA gets the landing page every time.
Invoke-WebRequest -Uri $url -OutFile $zip -UseBasicParsing -UserAgent "curl/8.0.1"
} catch { } catch {
Write-Host "ERROR: Download failed - $($_.Exception.Message)" -ForegroundColor Red Write-Host "ERROR: Download failed - $($_.Exception.Message)" -ForegroundColor Red
Write-Host "Check your internet connection, or ask IT if winscp.net / sourceforge.net are blocked." -ForegroundColor Yellow Write-Host "Check your internet connection, or ask IT if winscp.net / sourceforge.net are blocked." -ForegroundColor Yellow
@@ -21,7 +24,7 @@ try {
$fileInfo = Get-Item $zip $fileInfo = Get-Item $zip
if ($fileInfo.Length -lt 1MB) { if ($fileInfo.Length -lt 1MB) {
Write-Host "ERROR: Downloaded file is only $($fileInfo.Length) bytes - too small to be WinSCP." -ForegroundColor Red Write-Host "ERROR: Downloaded file is only $($fileInfo.Length) bytes - too small to be WinSCP." -ForegroundColor Red
Write-Host "This usually means antivirus, a firewall, or a web filter intercepted the download and replaced it with a block/warning page instead of letting the real file through." -ForegroundColor Yellow Write-Host "This is usually winscp.net serving its 'please wait' landing page instead of the real file, or antivirus/a firewall intercepting the download." -ForegroundColor Yellow
$preview = Get-Content -Path $zip -TotalCount 15 -ErrorAction SilentlyContinue $preview = Get-Content -Path $zip -TotalCount 15 -ErrorAction SilentlyContinue
if ($preview) { if ($preview) {