How do you download a file from an https site that requires username and password

Stacy Bell 41 Reputation points
2021-12-29T16:23:40.413+00:00

How do you download a file from an https site that requires username and password? I tried both:

[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls, [Net.SecurityProtocolType]::Tls11, [Net.SecurityProtocolType]::Tls12, [Net.SecurityProtocolType]::Ssl3
[Net.ServicePointManager]::SecurityProtocol = "Tls, Tls11, Tls12, Ssl3"
$download_url = "C:\Users\me\Downloads\Monthly Report.csv"
$local_path = "C:\Users\me\Downloads\Monthly Report.csv"
$user = "myusername"
$pass = "mypassword"
$WebClient = New-Object System.Net.WebClient
$WebClient.Credentials = New-Object System.Net.NetworkCredential($user, $pass)
$WebClient.DownloadFile($download_url, $local_path)

[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls, [Net.SecurityProtocolType]::Tls11, [Net.SecurityProtocolType]::Tls12, [Net.SecurityProtocolType]::Ssl3
[Net.ServicePointManager]::SecurityProtocol = "Tls, Tls11, Tls12, Ssl3"
$download_url = "C:\Users\me\Downloads\Monthly%20Report.csv"
$local_path = "C:\Users\me\Downloads\Monthly%20Report.csv"
$user = "myusername"
$pass = "mypassword"
$WebClient = New-Object System.Net.WebClient
$WebClient.Credentials = New-Object System.Net.NetworkCredential($user, $pass)
$WebClient.DownloadFile($download_url, $local_path)

I'm getting an error: [Download File] Error: Download failed: The request was aborted: Could not create SSL/TLS secure channel.

Windows for business | Windows Server | User experience | PowerShell
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. MotoX80 36,401 Reputation points
    2021-12-29T16:51:10.793+00:00

    $download_url = "C:\Users\me\Downloads\Monthly%20Report.csv"

    For starters you have to point to an actual web site address and not local file name that's on the C drive. The download url should be something like HTTPS://www.SomeSite.com/SomethingElse/

    https://theitbros.com/download-file-powershell/


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.