gpt4 book ai didi

powershell - 尝试使用 Powershell 下载文件时出错

转载 作者:行者123 更新时间:2023-12-02 23:54:14 26 4
gpt4 key购买 nike

当我尝试从 https URL 下载文件时,出现以下错误。我正在使用 Power Shell 3.0

外壳脚本

$Username = 'user'
$Password = 'password'
$Url = "url"
$Path = "path"
$WebClinet = New-Object System.Net.WebClient
$WebClient.Credentials = New-Object System.Net.Networkcredential($Username, $Password)
$WebClient.DownloadFile( $Url, $Path )

错误:

使用“2”个参数调用“DownloadFile”时发生异常:“WebClient 请求期间发生异常。”在行:7 字符:1+ $WebClient.DownloadFile( $Url, $Path )

有什么建议吗?

最佳答案

将您现有的 powershell 代码包装在一个 try catch block 中,并写出异常详细信息,以便了解导致问题的实际错误。

Try
{
$Username = 'user'
$Password = 'password'
$Url = "url"
$Path = "path"
$WebClient = New-Object System.Net.WebClient
$WebClient.Credentials = New-Object System.Net.Networkcredential($Username, $Password)
$WebClient.DownloadFile( $Url, $Path )
}
Catch [Exception]
{
Write-Host $_.Exception | format-list -force
}

而且您的代码中也有错别字。检查您的变量名称。

关于powershell - 尝试使用 Powershell 下载文件时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49609509/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com