0

I need to download a file daily from a website where date will passed. I tried using following code -

$url = "https://www.theocc.com/webapps/threshold-securities?reportDate=20190730"
$output = "C:\Users\Himanshu.Vats\Downloads\"
Invoke-WebRequest -Uri $url -OutFile $output

But it is giving error -

Invoke-WebRequest : The underlying connection was closed: An unexpected error occurred on a send. At line:3 char:1 + Invoke-WebRequest -Uri $url -OutFile $output + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest], WebException + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand

Himanshu
  • 1
  • 1
  • 2
  • I tried this also - $WebClient = New-Object System.Net.WebClient $WebClient.DownloadFile("https://www.theocc.com/webapps/threshold-securities","C:\Users\Himanshu.Vats\Downloads\") and this giving error - – Himanshu Aug 01 '19 at 15:09
  • 5
    Please see this post: https://stackoverflow.com/questions/41618766/powershell-invoke-webrequest-fails-with-ssl-tls-secure-channel/41618979#41618979 (ie. try setting `[Net.ServicePointManager]::SecurityProtocol = 'Tls11,Tls12'` before calling `Invoke-WebRequest`) – Mathias R. Jessen Aug 01 '19 at 15:15
  • 1
    Possible duplicate of [Powershell Invoke-WebRequest Fails with SSL/TLS Secure Channel](https://stackoverflow.com/questions/41618766/powershell-invoke-webrequest-fails-with-ssl-tls-secure-channel) – AussieJoe Aug 01 '19 at 15:43

1 Answers1

1

It's because your path is not a path file (you have a '\' to end path)

try this:

$url = "https://www.theocc.com/webapps/threshold-securities?reportDate=20190730"
$output = "C:\Users\Himanshu.Vats\Downloads\result.csv"
Invoke-WebRequest -Uri $url -OutFile $output
Esperento57
  • 16,521
  • 3
  • 39
  • 45