# Download file from HTTPS Website

**URL:** <https://forums.powershell.org/t/download-file-from-https-website/5297>\
**Category:** PowerShell Help\
**Created:** [December 2, 2015, 7:54pm UTC](https://forums.powershell.org/t/download-file-from-https-website/5297 "2015-12-02T19:54:42Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![derek-ebeling1](https://avatars.discourse-cdn.com/v4/letter/d/3ab097/32.png) [@derek-ebeling1](https://forums.powershell.org/u/derek-ebeling1)\
**Post date:** [December 2, 2015, 7:54pm UTC](https://forums.powershell.org/t/download-file-from-https-website/5297/1 "2015-12-02T19:54:42Z")

</div>

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 = “[https://www.website.com/get.jsp?Code=TEXT](https://www.website.com/get.jsp?Code=TEXT)”  
$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)
- 

```auto
  + CategoryInfo : NotSpecified: (:) [], MethodInvocationException
  + FullyQualifiedErrorId : WebException

```

Thank you in advance,  
Derek

---

<div class="post-metadata">

**Author:** ![donj](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/donj/32/137_2.png) [@donj](https://forums.powershell.org/u/donj)\
**Post date:** [December 3, 2015, 2:17am UTC](https://forums.powershell.org/t/download-file-from-https-website/5297/2 "2015-12-03T02:17:22Z")

</div>

At a glance, the code looks fine to me. Since you’re really using .NET, and not PowerShell, you might try looking in [StackOverflow.com](http://StackOverflow.com) since there’s a lot more .NET programmers hanging out there. For example, [Powershell script to download file, having trouble setting up a secure connection - Stack Overflow](http://stackoverflow.com/questions/146973/powershell-script-to-download-file-having-trouble-setting-up-a-secure-connectio?s=1%7C0.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.

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:43pm UTC](https://forums.powershell.org/t/download-file-from-https-website/5297/3 "2024-05-16T20:43:31Z")

</div>


