下载所有.bak文件 [英] Download all the .bak files
问题描述
我正在尝试使用凭据从网页下载所有.bak文件。但有时候,它工作正常,有时却不行。下面是我正在使用的脚本:
I am trying to download all the .bak files from the webpage using credentials. But sometime, it is working fine and sometimes its not. Below is the script which I am using:
$ Username ='xxxx'
$ Password ='yyyyy'
$ webclient = New-Object System.Net.webclient
$ source =" https://somesite.com/"
$ destination =" E:\ myfolder"
#以下行返回网页中的链接
$ WebClient.Credentials = New-Object System.Net.Networkcredential($用户名,$密码)
$ testcode1 = $ webclient.downloadstring($ source)-split"< a \\\ +" | %{[void]($ _ -match" ^ href = [`'`"]([^`'`"> \s] * .bak)"); $ match [1]}
$
foreach($ test in $ testcode1){
;&NBSP; #$ Destination =" $ destination \ $ line"
#如果新目录不存在,请创建一个新目录
if(!(Test-Path $ Destination))
{
New-Item $ Destination -type目录-Force
}¥b $ b
$ WebClient.Credentials = New-Object System.Net.Networkcredential($ Username,$ Password)
$ webclient.downloadfile($ source + $ line,$ destination + $ line)
}
$Username = 'xxxx'
$Password = 'yyyyy'
$webclient = New-Object System.Net.webclient
$source = "https://somesite.com/"
$destination = "E:\myfolder"
#The following line returns the links in the webpage
$WebClient.Credentials = New-Object System.Net.Networkcredential($Username, $Password)
$testcode1=$webclient.downloadstring($source) -split "<a\s+" | %{ [void]($_ -match "^href=[`'`"]([^`'`">\s]*.bak)"); $matches[1]}
foreach ($line in $testcode1) {
#$Destination = "$destination\$line"
#Create a new directory if it doesn't exist
if (!(Test-Path $Destination))
{
New-Item $Destination -type directory -Force
}
$WebClient.Credentials = New-Object System.Net.Networkcredential($Username, $Password)
$webclient.downloadfile($source + $line , $destination + $line )
}
每次我得到的执行时误差低于此值。
Everytime I am getting the below error while executing.
无法索引到空数组。
在C:\ Users \ uswmnl09 \Desktop \Download\Test.ps1:37 char:118
+ ..."> \s] * .bak)"); $匹配[1]}
+&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP ;&NBSP; ~~~~~~~~~~~
+ CategoryInfo :InvalidOperation:(:) [],RuntimeException
+ FullyQualifiedErrorId:NullArray
无法索引到空数组。
在C:\ Users \ uswmnl09 \Desktop \\ \\Download\Test.ps1:37 char:118
+ ..."> \s] * .bak)"); $匹配[1]}
+&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP ;&NBSP; ~~~~~~~~~~~
+ CategoryInfo :InvalidOperation:(:) [],RuntimeException
+ FullyQualifiedErrorId:NullArray
无法索引到空数组。
在C:\ Users \ uswmnl09 \Desktop \\ \\Download\Test.ps1:37 char:118
+ ..."> \s] * .bak)"); $匹配[1]}
+&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP ;&NBSP; ~~~~~~~~~~~
+ CategoryInfo :InvalidOperation:(:) [],RuntimeException
+ FullyQualifiedErrorId:NullArray
Cannot index into a null array.
At C:\Users\uswmnl09\Desktop\Download\Test.ps1:37 char:118
+ ... ">\s]*.bak)"); $matches[1]}
+ ~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : NullArray
Cannot index into a null array.
At C:\Users\uswmnl09\Desktop\Download\Test.ps1:37 char:118
+ ... ">\s]*.bak)"); $matches[1]}
+ ~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : NullArray
Cannot index into a null array.
At C:\Users\uswmnl09\Desktop\Download\Test.ps1:37 char:118
+ ... ">\s]*.bak)"); $matches[1]}
+ ~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : NullArray
有时我收到以下错误:
异常调用" DownloadString"用"1"表示"1"。参数:"远程服务器返回错误:(407)需要代理验证。"\\ n \\ b
在C:\ Users \ uswmnl09 \Desktop \Download \ Test。 ps1:37 char:1
+ $ testcode1 = $ webclient.downloadstring($ source)-split"< a \\\ +" | %{[void]($ _ -mat ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~
&NBSP;&NBSP;&NBSP; + CategoryInfo&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;:NotSpecified:(:) [],MethodInvocationException
+ FullyQualifiedErrorId:WebException
Exception calling "DownloadString" with "1" argument(s): "The remote server returned an error: (407) Proxy Authentication Required."
At C:\Users\uswmnl09\Desktop\Download\Test.ps1:37 char:1
+ $testcode1=$webclient.downloadstring($source) -split "<a\s+" | %{ [void]($_ -mat ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : WebException
对此有任何帮助。
推荐答案
行"
The line "
testcode1 =
testcode1=
webclient.downloadstring(
webclient.downloadstring(
这篇关于下载所有.bak文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!