Windows – how to use bitsadmin.exe (Windows) download file from authenticated Jenkins server

Jenkinswindows

I am aware of using following command to download files from Jenkins server if the workspace is anonymous access:

bitsadmin.exe /transfer replica /priority FOREGROUND http://1.1.1.1:8080/job/dump_data/ws/dump_data.zip %WORKSPACE%\dump_data.zip

But what if the Jenkins server is authenticated by username/password ?

EDIT: /setcredentials works, but one problem is that I can only use /create, /addfile, /resume, then /complete. How can I wait till transfer finish then continue the batch script?

EDIT:
Further test shows /setcredential didn't work. The previous test shows it works because my Jenkins allow anonymous access at that time.
I captured the packet when using the bitadmin. It shows http request is HEAD without any credential information.
If I use curl-win to download, the http request is GET with basic authentication username and password.

Best Answer

If you need to set credentials on a BITS job, you'd use the /setcredentials switch.

 /SETCREDENTIALS job target scheme username password
     Adds credentials to a job.
     target may be either SERVER or PROXY
     scheme may be BASIC, DIGEST, NTLM, NEGOTIATE, or PASSPORT.

The excellent ss64 command reference for BITSadmin can be found here.