sharepoint online – POWERSHELL Webclient Download / Upload with specification "The request has been canceled: The request has been canceled."

The Powershell code for downloading and uploading a Sharepoint file triggers an error in the download and upload functions.
Error is: Exception when calling "UploadFile" with "3" arguments: "The request was aborted: The request was aborted."

Any idea, what is the cause?

For your information, I can manually download files from SharePoint!

$ 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")
To attempt
{
$ client.DownloadFile ($ SPFileUrl, $ DownloadLocalPath)
}
fishing
{
Write-Message $ LogFileName "` nDownload file failed "
$ ErrorMessage = $ _. Exception.Message
Write-Message $ LogFileName "` n $ ErrorMessage "
}
$ client.Dispose ()

As I said, the above code returns errors. Exception: Calling "UploadFile" with "3" arguments: "The request was aborted: The request was aborted."

And as a solution, code was tried by the following websites

$ timeoutWebclientCode = @ "
with system;
with System.Net;

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

protect override 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;
}
}
Rückholanfrage;
}

public ExtendedWebClient ()
{
Timeout = 100000; // Default HTTP request timeout
}

}
"@;

And the above does not work if the same error is output.

Invoke Webrequest is the next thing I've tried

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

What do I get Invoke-WebRequest for: The remote server returned an error: (401) Unauthorized.

Please help me!