start-bitstransfer :该进程无法访问该文件,因为它正在被另一个进程使用

start-bitstransfer :该进程无法访问该文件,因为它正在被另一个进程使用

在 powershell 中,我无法使用 BITS Transfer 复制其他进程(在我的情况下是服务)正在使用的文件。

Start-BitsTransfer -Source "E:/path1/dir1/file1.txt" -Destination

生产

start-bitstransfer:该进程无法访问该文件,因为它正在被另一个进程使用。

但是 Copy-Item 没有这样的问题。不幸的是,我无法使用 Copy-Item,因为它没有进入低优先级/后台模式的选项,因此可能会给我正在下载的服务器带来太大的压力。

答案1

答案2

尝试在异步模式下使用:

$Job = Start-BitsTransfer -Source https://Server1.TrustedDomain.com/File1.zip `
       -Destination d:\temp\downloads\ -Asynchronous

while (($Job.JobState -eq "Transferring") -or ($Job.JobState -eq "Connecting")) `
       { sleep 5;} # Poll for status, sleep for 5 seconds, or perform an action.

Switch($Job.JobState)
{
    "Transferred" {Complete-BitsTransfer -BitsJob $Job}
    "Error" {$Job | Format-List } # List the errors.
    default {"Other action"} #  Perform corrective action.
}

https://docs.microsoft.com/en-us/windows/win32/bits/using-windows-powershell-to-create-bits-transfer-jobs

我通过 VPN 从 PC 复制到网络驱动器时遇到了同样的错误,使用我尝试使用 Process Monitor 复制的文件名搜索钩子没有返回任何内容。我想说这里面肯定有些线程问题。Async BitsTransfer 更麻烦,但对错误的适应性很强。

根据您调用 bittransfer 的方式,您可能需要使用完整位传输命令

相关内容