Invoke-WebRequest large file upload - underlying connection was closed

I’m trying to upload a large file to Nexus repo using Invoke-WebRequest and getting the following error message.

Invoke-WebRequest : The underlying connection was closed: An unexpected error occurred on a send.

[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
$publishUrl = "https://nexusurl/"
$filePath = "C:\TEMP\"
$Username = "admin"
$Password = "adminpass"
$params = @{
    UseBasicParsing = $true
    Uri             = $publishUrl
    Method          = "POST"
    InFile          = $filePath
    Headers         = @{
        ContentType   = "application/zip"
        Authorization = "Basic $([System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes("$Username`:$Password")))"
Invoke-WebRequest @params -TimeoutSec 3600

It seems like uploading 1-2gig file works fine but anything larger than that, Im getting the error.
same question is posted in powershell - Invoke-WebRequest large file upload - underlying connection was closed - Stack Overflow

Welcome to the forum. :wave:t4:

The error might not be caused by PowerShell itself. So there might be nothing we can advice to circumvent this error from a PowerShell perspective. Have you tried it without the -TimeoutSec parameter?

Yes I’ve tried it without the -timeoutsec but still getting the same error message…

Can you upload a bigger file without PowerShell?

And BTW:

When you crosspost the same question at the same time to different forums you should at least post links to the other forums along with your question to avoid people willing to help you making their work twice or more.


1 Like

yes, I am able to upload large file manually without PowerShell.