我正在尝试使用 PowerShell 从我的 JFrog 存储库下载文件,但无法使其正常工作。
这是我得到的错误:
使用“2”个参数调用“DownloadFile”的异常:“底层连接已关闭:意外错误
发生在发送中。”
在 C:\Users\jelte\Documents\myproject\downloadExecutables1.ps1:16 char:1
+ $req.DownloadFile('https://myrepo.jfrog.io/myproject/libs-release-loca ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [],
方法调用异常
我使用的代码:
$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')
Run Code Online (Sandbox Code Playgroud)
我尝试过的事情:
Invoke-Webrequest,这有效,但速度非常慢。小智 1
尝试将这些行添加到脚本的开头。
$AllProtocols = [System.Net.SecurityProtocolType]'Tls12'
[System.Net.ServicePointManager]::SecurityProtocol = $AllProtocols
Run Code Online (Sandbox Code Playgroud)
我遇到了类似的情况,但没有提供非常丰富的错误消息,问题显然只是我需要将 powershell 使用的安全协议设置为 Tls 1.2。
| 归档时间: |
|
| 查看次数: |
951 次 |
| 最近记录: |