我正在尝试使用PowerShell从我的JFrog存储库下载文件,但无法正常工作。
这是我得到的错误:
Exception calling "DownloadFile" with "2" argument(s): "The underlying connection was closed: An unexpected error occurred on a send." At C:\Users\jelte\Documents\myproject\downloadExecutables1.ps1:16 char:1 + $req.DownloadFile('https://myrepo.jfrog.io/myproject/libs-release-loca ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [], MethodInvocationException
我使用的代码:
$usernameVar = "JFROG_USERNAME"
$username = (get-item env:$usernameVar).Value
$passwordVar = "JFROG_PASSWORD"
$password = (get-item env:$passwordVar).Value
$auth = 'Basic ' + [System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes($username+":"+$password))
$req = New-Object System.Net.WebClient
$req.Headers.Add('Authorization', $auth)
$installersFolder = $PSScriptRoot + '\prerequisites\executables'
If(!(test-path $installersFolder))
{
New-Item -ItemType Directory -Force -Path $installersFolder
}
$req.DownloadFile('https://myrepo.jfrog.io/myproject/libs-release-local/binary/com/targetexecutable/9.3.240/executable-9.3.240.exe', $installersFolder + '\executable-9.3.240.exe')
我尝试过的事情:
Invoke-Webrequest
,此方法有效,但速度非常慢。答案 0 :(得分:0)
尝试将这些行添加到脚本的开头。
$AllProtocols = [System.Net.SecurityProtocolType]'Tls12'
[System.Net.ServicePointManager]::SecurityProtocol = $AllProtocols
我经历了类似的事情,但没有非常有用的错误消息,并且问题显然只是我需要将powershell所使用的安全协议设置为Tls 1.2。