Every so often, one of my favourite cycle training video vendors releases a new video or two. These videos are generally multi-gigabyte files and downloading them through a browser, especially over a possibly-flaky wireless network, can be an exercise in frustration. Browser crashes happen, network blips happen, sometimes you even exit the browser session without thinking and terminate a nearly-complete download. That’s why I generally use BITS to download them, in PowerShell. How? Pretty simple, really. Just use the Start-BITSTransfer cmdlet, specifying source and destination, and you’re away.
Start-BITSTransfer http://www.myawesomevideosite.com/files/somebigfile $home\Downloads\somebigfile.zip
Running that will start your download, fire up a progress bar and some time later, you’ll have a usable file in your downloads folder. Of course, doing it this way will take over your PowerShell session for the duration of the download. Which is rubbish. Who wants to clutter up their desktop session with PowerShell windows? That’s why I do it asyncronously
Start-BITSTransfer -source http://www.myawesomevideosite.com/files/somebigfile -destination $home\Downloads\somebigfile.zip -asyncronous
Which is great. I can carry on using my PowerShell session in the foreground, or even close it, without interrupting the download process. I can even fire up another download next to the first one and just let them run in the background.
But how do I check on how the download is going?
I can use Get-BITSTransfer in any PowerShell session, and the BITS service will report the status of any currently running BITS jobs, like so
C:\> Get-BitsTransfer | Format-List JobId : d3c1a9a0-68f0-4831-939b-95ab0122476c DisplayName : BITS Transfer TransferType : Download JobState : Transferring OwnerAccount : DOMAIN\jason.brown Priority : Foreground TransferPolicy : Always FilesTransferred : 0 FilesTotal : 1 BytesTransferred : 208207360 BytesTotal : 2430734370 CreationTime : 27/10/2015 12:56:17 PM ModificationTime : 27/10/2015 1:09:08 PM MinimumRetryDelay : NoProgressTimeout : TransientErrorCount : 1 ProxyUsage : SystemDefault ProxyList : ProxyBypassList : JobId : 1d0a4b78-7b9c-4977-9b32-b962c754e8f6 DisplayName : BITS Transfer TransferType : Download JobState : Transferring OwnerAccount : DOMAIN\jason.brown Priority : Foreground TransferPolicy : Always FilesTransferred : 0 FilesTotal : 1 BytesTransferred : 15883778 BytesTotal : 2394848910 CreationTime : 27/10/2015 1:08:02 PM ModificationTime : 27/10/2015 1:09:08 PM MinimumRetryDelay : NoProgressTimeout : TransientErrorCount : 1 ProxyUsage : SystemDefault ProxyList : ProxyBypassList :
You could even pick out the BytesTransferred and BytesTotal properties and do some quick math on them to see the percentage of download complete. There’s a whole load of stuff you can do with BITS to make your downloads complete more reliably.
Once you see your downloads are done, use the Complete-BitsTransfer cmdlet to save the file from its temporary location to your target.
Get-BitsTransfer | Complete-BitsTransfer
I’d recommend checking out the Get-Help and Get-Command output for these cmdlets to find out more if you want to get more advanced, or I might do a future blog post with some more advanced stuff like changing priorities, or downloading a list of files from a CSV or database. You can even use this system to do reliable uploads. It’s really a very handy set of cmdlets.