简体   繁体   中英

What is the purpose of the Complete-BitsTransfer cmdlet?

PowerShell and Windows have a nice framework for transferring files called BITS. This can be used synchronously:

Start-BitsTransfer -Source \\remote_file_location -Destination .

There is an asynchronous flag to run the download in the background:

Start-BitsTransfer -Asynchronous -Source \\remote_file_location -Destination .

If you just run the job asynchronously, after a while it will show as transferred:

JobId                     DisplayName              TransferType             JobState                             
-----                     -----------              ------------             --------                 
cd070594-6103-44eb-b6c... BITS Transfer            Download                 Transferred

However, your file won't show up at destination until you run the Complete-BitsTransfer cmdlet:

Get-BitsTransfer | Complete-BitsTransfer

Until then, your file is apparently in limbo, somewhere on your computer (or in memory?). What is the purpose of this? Why doesn't windows directly place files at their destination as they arrive?

In situations where an event-driven automated process is going to do something as soon as the file is written, it lets you control the timing of that process by transferring the file to temp location, and the Complete process will write it to it's final destination.

eg if you were transferring a file to multiple systems to update a piece of client software, and need to make sure they all update at the same time, and that all of them update or none of them do.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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