%SystemRoot%System32 secrets: BITSAdmin

CLIAnother deprecated friend of mine. But I still like it, really. First of all because I haven’t still found enough time to get acquainted with all that *-BITSTransfer PowerShell comandlets. Second… Well, there is nothing for the “second”, naturally =) But still – it is a great command and I’d like to make a tribute to it with this article, because it is AWESOME! It is soooo powerful! Even though I used it usually just to be sure I would download the file regardless of network loss or whatever, it can do much more. Download or upload, retry these tasks, get some part of the file, set myriads of parameters, including authentication, use peer caching… Wow! =)

But again, usually I used it to download large files. Let’s take a look at one example.

Lets start with creating a download job:

BITSAdmin /CREATE /DOWNLOAD DownloadJob1

image

You can see that the job has been created and it has been assigned some GUID you can use later (but we’ll use it’s name in this example). Also as you can see we are being constantly notified about the command deprecation =( Let’s take a look at the job:

BITSadmin /LIST /VERBOSE

image

(Yeah, a LOT of information). Obviously, the job is currently empty (FILES: 0 / 0), so let’s add some files to it:

BITSadmin /ADDFILE DownloadJob1 <URL> <PathToSavedFile>

image

Added successfully and created a temp file already:

image

Let’s add one more:

image

and look at the second temporary file:

image

They are both of 0 bytes size yet. Now, once we have two files for our job to download, we can get more info from the job:

image

Here we can see both our files (JOB FILES) and… Can we just wait till the files get downloaded? No, because the job is not started at the moment (STATE: SUSPENDED). We need to start it and this is easy:

BITSADMIN /RESUME DownloadJob1

image

Now the job is in TRANSFERRING state, we can see how many bytes (BYTES) or files (FILES) has been transferred and so on. On this point something goes wrong and we get our network disconnected: image. Is it a problem for our downloads? Yes:

image

their state is TRANSIENT_ERROR. Should we worry about it? No, because as soon as network restores we’ll get our job QUEUD and then resumed automatically:

image

Looking at this big picture from time to time reentering /LIST command is boring, so we’ll monitor it in other way:

BITSadmin /MONITOR /REFRESH 1

image

which will refresh the state for our jobs occasionally (each 1 second in the example):

image

As soon as we get our files transferred:

image

we can just go to our download location and… Oh… Wait… What’s that?

image

The files do have appropriate size but their names… They are still temporary =( But don’t worry, just one more little step:

BITSadmin /COMPLETE downloadJob1

image

Oops. Seems like BITSadmin treats job names as case-sensitive. We should remember this, so let’s rewrite it in the correct way:

BITSadmin /COMPLETE DownloadJob1

image

Here we are! The files are here and no more job to do! I’m loving it © =)

image

Forgive me for that useless lesson: just couldn’t resist it Winking smile

If you are as amazed, as I am, here is some reading.

About these ads
This entry was posted in CLI Secrets, Tips'N'Tricks, Tools. Bookmark the permalink.

One Response to %SystemRoot%System32 secrets: BITSAdmin

  1. Pingback: BITS Transfer PowerShell cmdlets » IT, IS, etc…

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s