簡體   English   中英

powershell 位傳輸 object 引用未設置為 object 的實例

[英]powershell bitstransfer object reference not set to an instance of an object

我有一個用 C# 編寫的程序,它使用 powershell 位傳輸從機器上傳和下載文件。 它一直工作正常,直到今天上傳和下載停止工作並給出此錯誤。 似乎該錯誤是我機器的本地錯誤,因為其他機器可以正常使用 bitstransfer 並且重新啟動機器並沒有解決問題。 有人可以幫我嗎? 謝謝

PS Start-BitsTransfer -Source \\ip\data\filename.xml -Destination G:\\PLAYGROUND\\dir\\\
Start-BitsTransfer : Object reference not set to an instance of an object.
At line:1 char:19
+ Start-BitsTransfer <<<<  -Source \\ip\data\filename.xml -Destination G:\\PLAYGROUND\\dir\\\
    + CategoryInfo          : NotSpecified: (:) [Start-BitsTransfer], NullReferenceException
    + FullyQualifiedErrorId : System.NullReferenceException,Microsoft.BackgroundIntelligentTransfer.Management.NewBits
   TransferCommand


    PS Start-BitsTransfer -Source G:\\PLAYGROUND\\dir\\file.txt -Destination \\\\ip\\data\\\
Start-BitsTransfer : Object reference not set to an instance of an object.
At line:1 char:19
+ Start-BitsTransfer <<<<  -Source G:\\PLAYGROUND\\dir\\file.txt -Destination \\\\ip\\data\\\
    + CategoryInfo          : NotSpecified: (:) [Start-BitsTransfer], NullReferenceException
    + FullyQualifiedErrorId : System.NullReferenceException,Microsoft.BackgroundIntelligentTransfer.Management.NewBits
   TransferCommand

我改用復制命令修復了它。

我認為當您有大量異步作業時會發生這種情況。 在我的情況下,處於失敗或轉移狀態以及運行Get-BitsTransfer | Remove-BitsTransfer后的所有作業Get-BitsTransfer | Remove-BitsTransfer Get-BitsTransfer | Remove-BitsTransfer我能夠開始位傳輸。

我也遇到了這個。 如果我快速連續添加 60 次傳輸,我會開始出錯。 以下是我的處理方式:

try {
    $ErrorActionPreference = 'Stop'
    Start-BitsTransfer $downloadUrl -Description $assetName -Destination $assetDestinationFolder -Asynchronous | Out-Null
}
catch {
    #If too many transfers are queued at once the process begins to fail. This takes care of that problem.

    while ($true) {
        Write-Host "Queue full. Waiting for other downloads to finish. $((Get-BitsTransfer).Count) downloads in progress." -ForegroundColor Yellow

        Start-Sleep -Seconds 1

        Get-BitsTransfer | Format-Table -Property Description, JobState

        Get-BitsTransfer | Where-Object { $_.JobState -eq "Transferred" } | Complete-BitsTransfer

        Get-BitsTransfer | Where-Object { $_.JobState -like "*Error" -or $_.JobState -eq "Cancelled" } | ForEach-Object { $_ | Remove-BitsTransfer }

        try {
            Start-BitsTransfer $downloadUrl -Description $assetName -Destination $assetDestinationFolder -Asynchronous | Out-Null
            break;
        }
        catch {
            continue;
        }
    }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM