Question

I am learning about BITS, i found this source using google: http://www.rohitab.com/discuss/topic/28249-using-bits-to-downloadupload-files/

It works fine but the downloaded file is not saved with the specified name but with some random file name like: "BITxxxx.tmp" Lame thing is that it saves in the specified location but not using the specified name.

Anyone have experience with this ?

Was it helpful?

Solution

The question is pretty unclear but odds are high that you are forgetting to call IBackgroundCopyJob::Complete(). The file transfer is not finalized until BITS knows that you obtained the outcome of the transfer. If you don't call Complete() or Cancel() within 90 days then the temporary file is deleted.

You can poll for the transfer state by calling IBackgroundCopyJob::GetState(), but that's not terribly practical. You can call IBackgroundCopyJob::SetNotifyInterface to ask for a callback that tells you that the transfer is completed or failed. But that's not terribly practical either, it can take a while before the transfer completes, especially when the server is offline or otherwise occupied. A good way to do it is to ask BITS to run a program upon completion, use the IBackgroundCopyJob2::SetNotifyCmdLine(). You'll want to use the command line arguments to at least pass the jobID so you can get an interface pointer to the job again. This way the transfer will survive gross stuff like a reboot or an earthquake.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top