Download file from HTTPS Website

Welcome Forums General PowerShell Q&A Download file from HTTPS Website

This topic contains 1 reply, has 2 voices, and was last updated by

3 years, 3 months ago.

  • Author
  • #32532

    Points: 0
    Rank: Member

    I have an https website I need to download a file from, but nothing I do seems to work. I can navigate to the website by using the "internetexplorer.application" and log in successfully. But I cannot overcome the "save as" dialog that pops up at the bottom of the screen after l navigate to the file I want to download. I also cannot get the standard "downloadfile" command to work. Can someone please help me get the below pseudo code to be actual code. I am using powershell 2.0. Thanks.

    $username = "user"
    $password = "pass"

    $url = ""
    $path = "C:\documents\file.pdf"

    $web = New-Object System.Net.WebClient
    $web.Credentials = new-object System.Net.NetworkCredential($username, $password)
    $web.DownloadFile($url, $path)

    This returns:
    Exception calling "DownloadFile" with "2" argument(s): "The underlying connection was closed: An unexpected error occurred on a send."
    At line:28 char:1
    + $web.DownloadFile($url, $path)
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : WebException

    Thank you in advance,

  • #32555

    Points: 1,811
    Helping HandTeam Member
    Rank: Community Hero

    At a glance, the code looks fine to me. Since you're really using .NET, and not PowerShell, you might try looking in since there's a lot more .NET programmers hanging out there. For example,|0.1730 seems to discuss a similar problem. Because PowerShell v2 doesn't really make it easy to write callback handlers, you might not be able to do what you want.

The topic ‘Download file from HTTPS Website’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort