小编Ale*_*ith的帖子

Powershell 使用代理通过 HTTP 下载并检查远程文件大小在第二个文件上失败

我有一个正在开发的 powershell 脚本,它将通过代理从 HTTP 服务器下载文件,并在服务器上包含 UN/PW。

我的文件下载正常,但有些文件非常大,所以我一直在添加一个函数来检查文件是否已更改(检查大小)。这适用于第一个文件。但它在这一行的第二个文件上超时:

$test = $wc2.OpenRead($source) | Out-Null)
Run Code Online (Sandbox Code Playgroud)

下面列出了我的脚本的代码(不包括凭据)。我很感激有关如何正确关闭连接(因为我怀疑没有发生)或如何使用 Powershell 通过 HTTP 获取远程文件大小的建议。

Function getWebClient {
    $webClient = new-object System.Net.WebClient 

    $pxy = new-object System.Net.WebProxy $proxy  
    $pxy.Credentials = New-Object System.Net.NetworkCredential ("tnad\$proxy_un", "$proxy_pw") 
    $webClient.proxy=$pxy  
    $webClient.Headers.Add("user-agent", "Windows Powershell WebClient Header") 

    $WebClient.Credentials = New-Object System.Net.Networkcredential($un, $pw)

    return $WebClient
}

foreach ($ds in $datasetsTest) {
    Write-Host "Checking: $ds"
    $source = "$server$ds"
    $dest = "$destFolder$ds"

    #Test whether the destination file already exists, if it exists, compare file sizes.
    $destExists = Test-Path $dest …
Run Code Online (Sandbox Code Playgroud)

powershell http

5
推荐指数
1
解决办法
3264
查看次数

标签 统计

http ×1

powershell ×1