sharepoint online – POWERSHELL WebClient Download / Upload giving "The request has been aborted: the request has been canceled."

The Powershell code for downloading and downloading a file from Sharepoint returns an error for the download and download functions.
Error: Exception calling "UploadFile" with "3" argument (s): "The request has been aborted: the request has been canceled."

Do you have any idea of ​​the cause of this?

For your information, I can download the file from SharePoint manually!

$ SPFileUrl = $ SPCodeDropCommanPath + $ ApplicationFolder + "/" + "$ SPFileName"
$ DownloadLocalPath = [System.IO.Path]:: Combine ("$ WorkingDir", "$ SPFileName")

$ SecurePassword = $ SPPassword | ConvertTo-SecureString -AsPlainText -Force
$ client = New-Object System.Net.WebClient
$ client.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials ($ SPUsername, $ SecurePassword)
$ client.Headers.Add ("X-FORMS_BASED_AUTH_ACCEPTED", "f")
try
{
$ client.DownloadFile ($ SPFileUrl, $ DownloadLocalPath)
}
capture
{
Write-Message $ LogFileName "` The nDownload File Failed "
$ ErrorMessage = $ _. Exception.Message
Write-Message $ LogFileName "` n $ ErrorMessage "
}
$ client.Dispose ()

As I said, the code above returns an error. Exception calling "UploadFile" with one or more arguments "3": "The request has been aborted: the request has been canceled."

And as a solution, from the websites below, the code has been tried

$ timeoutWebclientCode = @ "
using the system;
using System.Net;

Public class ExtendedWebClient: WebClient
{
public int Timeout {get; together; }
public new bool AllowWriteStreamBuffering {get; together; }

Protected Replace WebRequest GetWebRequest (Uri Address)
{
var request = base.GetWebRequest (address);
if (request! = null)
{
request.Timeout = Timeout;
var httpRequest = request as HttpWebRequest;
if (httpRequest! = null)
{
httpRequest.AllowWriteStreamBuffering = false;
}
}
return request;
}

public ExtendedWebClient ()
{
Waiting time = 100000; // the default value of the standard HTTP request timeout
}

}
"@;

And the above does not work either by giving the same error.

Invoke-Webrequest is the next thing I was trying

Invoke-WebRequest -Uri "DownloadURL" -OutFile "LocalPath" -Credential $ cred

Invoke-WebRequest: The remote server returned an error: (401) Not allowed.

Please help me on this point!