4

i have a program written in C# that uses powershell bitstransfer to upload and download a file from a machine. its been working fine until today when the upload and download stopped working giving this error. It seems like the error is local to my machine because other machines work properly with bitstransfer and restarting the machine didn't fix the problem. Could someone help me out? Thanks

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
  • Just for clarity: you don't need to escape `\\` in source and destination parameter. – CB. Nov 26 '12 at 14:48

3 Answers3

2

I fixed it by using the copy command instead.

McGarnagle
  • 101,349
  • 31
  • 229
  • 260
1

I think this happens when you have a high number of asynchronous jobs. All jobs in my case where either in failed or transferred state and after running Get-BitsTransfer | Remove-BitsTransfer I was able to start bits transfer.

ArdentLearner
  • 712
  • 7
  • 20
0

I ran into this as well. If I added 60 transfers in quick succession I'd start getting errors. Here's how I handled it:

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;
        }
    }
}
Keith Banner
  • 602
  • 1
  • 10
  • 15