这是我下载文件的脚本,我替换了下载的网址,因为它是一个私有云站点,我到处搜索,他们都说这是在旧版本的 PS 中下载的正确方法,但我不断收到错误
Exception calling "DownloadFile" with "2" argument(s): "An exception occurred during a WebClient request." At line:60 char:25 + $client.DownloadFile <<<< ($url, $targetFile) + CategoryInfo : NotSpecified: (:) [], MethodInvocationException + FullyQualifiedErrorId : DotNetMethodException
$url = "(download url)"
$path = "C:\temp\jre-7u71-windows-i586.exe"
# param([string]$url, [string]$path)
if(!(Split-Path -parent $path) -or !(Test-Path -pathType Container (Split-Path -parent $path))) {
$targetFile = Join-Path $pwd (Split-Path -leaf $path)
}
"Downloading [$url]`nSaving at [$path]"
$client = new-object System.Net.WebClient
$client.DownloadFile($url, $targetFile)
#$client.DownloadData($url, $targetFile)
$path
我遇到了同样的问题,您声明 $client 变量的方式似乎存在问题。
老帖子,但这对我在 Windows 7、PowerShell 2.0 中有效
请注意 URL 和 Path 已更改。
$url = "http://www.7-zip.org/a/7z1604.exe"
$path = "C:\temp\7z1604.exe"
# param([string]$url, [string]$path)
if(!(Split-Path -parent $path) -or !(Test-Path -pathType Container (Split-Path -parent $path))) {
$targetFile = Join-Path $pwd (Split-Path -leaf $path)
}
(New-Object Net.WebClient).DownloadFile($url, $path)
$path
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)