简体   繁体   English

使用C#中的BITS(后台智能传输服务)

[英]Using BITS (Background Intelligent Transfer Service) from C#

I'd like to write some code that uses BITS for copying very large files between disks on the same server (the second disk being a SAN level clone\\snapshot). 我想编写一些代码,使用BITS在同一服务器上的磁盘之间复制非常大的文件(第二个磁盘是SAN级别的clone \\ snapshot)。

I looked into BITS as i thought it would be a good way to get progress\\percentage complete data on the transfers, as well as resume functionality etc 我研究了BITS,因为我认为这是获取进度\\传输中完整数据的百分比以及恢复功能等的好方法

I have a lot of hosted Powershell and I thought i'd have a stab at using the inbuilt BITS cmdlets, as this would be a super quick way of doing it, i could write wrappers to get the stuff i need etc Unfortunately i ran into this: 我有很多托管的Powershell,我想使用内置的BITS cmdlet会很麻烦,因为这将是一种超快速的方式,我可以编写包装程序来获取所需的东西,等等。不幸的是,我遇到了这个:

When you use *-BitsTransfer cmdlets from within a process that runs in a noninteractive context, such as a Windows service, you may not be able to add files to BITS jobs, which can result in a suspended state. 在非交互上下文中运行的进程(例如Windows服务)中使用* -BitsTransfer cmdlet时,可能无法将文件添加到BITS作业中,这可能导致挂起状态。 For the job to proceed, the identity that was used to create a transfer job must be logged on. 为了使作业继续进行,必须登录用于创建传输作业的标识。 For example, when creating a BITS job in a PowerShell script that was executed as a Task Scheduler job, the BITS transfer will never complete unless the Task Scheduler's task setting "Run only when user is logged on" is enabled." 例如,当在作为任务计划程序作业执行的PowerShell脚本中创建BITS作业时,除非启用任务计划程序的任务设置“仅在用户登录时运行”,否则BITS传输将永远不会完成。

Doing anything through an impersonated Powershell runspace throws up the following error: 通过模拟的Powershell运行空间执行任何操作都会引发以下错误:

The operation being requested was not performed because the user has not logged on to the network. 由于用户尚未登录网络,因此未执行所请求的操作。 The specified service does not exist. 指定的服务不存在。 (Exception from HRESULT: 0x800704DD)" (来自HRESULT的异常:0x800704DD)”

My web service is running as AppPoolIdentity, I impersonate when needed to do stuff. 我的Web服务以AppPoolIdentity的身份运行,需要时我会模拟。 It makes sense this doesn't work via hosted Powershell, but can anyone think of a workaround? 这在托管的Powershell中不起作用是有道理的,但是有人能想到解决方法吗? If this isn't possible, do i have any alternatives? 如果这不可能,我是否有其他选择?

I was thinking of using BITS Compact Server as an alternative, but the documentation is ancient. 我曾考虑过使用BITS Compact Server作为替代方案,但是该文档是古老的。

Have you thought of using robocopy? 您是否考虑过使用robocopy? Running with the /ZB switch has always worked well for me, and you can improve performance with /J which enables unbuffered I/O. 使用/ ZB开关运行对我来说一直很好,并且可以使用/ J启用无缓冲I / O来提高性能。 For output, run with /ETA and /TEE as well. 对于输出,还要与/ ETA和/ TEE一起运行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM