# BITS transfer with github

**URL:** <https://forums.powershell.org/t/bits-transfer-with-github/8652>\
**Category:** PowerShell Help\
**Created:** [May 18, 2017, 7:21am UTC](https://forums.powershell.org/t/bits-transfer-with-github/8652 "2017-05-18T07:21:20Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![r3dlin3](https://avatars.discourse-cdn.com/v4/letter/r/a9adbd/32.png) [@r3dlin3](https://forums.powershell.org/u/r3dlin3)\
**Post date:** [May 18, 2017, 7:21am UTC](https://forums.powershell.org/t/bits-transfer-with-github/8652/1 "2017-05-18T07:21:20Z")

</div>

Hi,

I’m trying to use BITS transfer to get binary files (release) from github.  
However, I always get a 403 error. For instance:

```
PS> Start-BitsTransfer -Source https://github.com/Microsoft/MIMWAL/releases/download/v2.17.0414.0/MIMWAL-2.17.0414.0.zip C:\tmp\foo.zip
Start-BitsTransfer : HTTP status 403: The client does not have sufficient access rights to the requested server object.
At line:1 char:1
+ Start-BitsTransfer -Source https://github.com/Microsoft/MIMWAL/releases/download ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : InvalidOperation: (:) [Start-BitsTransfer], Exception
    + FullyQualifiedErrorId : StartBitsTransferCOMException,Microsoft.BackgroundIntelligentTransfer.Management.NewBits
   TransferCommand
```

It is working fine with WebClient:

```
> $wc = New-Object System.Net.WebClient
> $wc.DownloadFile("https://github.com/Microsoft/MIMWAL/releases/download/v2.17.0414.0/MIMWAL-2.17.0414.0.zip","C:\tmp\foo.zip")
> Test-Path "C:\tmp\foo.zip"
True
```

Do you see any reason why it does not work with BITS?

---

<div class="post-metadata">

**Author:** ![donj](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/donj/32/137_2.png) [@donj](https://forums.powershell.org/u/donj)\
**Post date:** [May 22, 2017, 6:00am UTC](https://forums.powershell.org/t/bits-transfer-with-github/8652/2 "2017-05-22T06:00:50Z")

</div>

That is weird. Unfortunately, BITS is a little opaque. It’s clearly doing something different, but I’d need to do, like, a packet capture to compare the two and see what was up.

---

<div class="post-metadata">

**Author:** ![diego-perez-botero](https://avatars.discourse-cdn.com/v4/letter/d/977dab/32.png) [@diego-perez-botero](https://forums.powershell.org/u/diego-perez-botero)\
**Post date:** [January 12, 2018, 4:51pm UTC](https://forums.powershell.org/t/bits-transfer-with-github/8652/3 "2018-01-12T16:51:57Z")

</div>

See updated post below.

---

<div class="post-metadata">

**Author:** ![diego-perez-botero](https://avatars.discourse-cdn.com/v4/letter/d/977dab/32.png) [@diego-perez-botero](https://forums.powershell.org/u/diego-perez-botero)\
**Post date:** [January 12, 2018, 4:59pm UTC](https://forums.powershell.org/t/bits-transfer-with-github/8652/4 "2018-01-12T16:59:26Z")

</div>

**PROBLEM**  
Downloading files from [GitHub.com](http://GitHub.com) fails with HTTP 403 when going through BITS (e.g., using [Start-BitsTransfer](https://technet.microsoft.com/en-us/library/dd819420.aspx)), but succeeds when a simpler API is used (e.g., System.Net.WebClient).

**ROOT CAUSE**  
Before beginning a download, BITS sends an HTTP HEAD request to the server in order to figure out the remote file’s size, timestamp, etc. This is especially important for [BranchCache-based BITS transfers](https://msdn.microsoft.com/en-us/library/windows/desktop/aa964314(v=vs.85).aspx) and is the reason why server-side HTTP HEAD support is listed as an [HTTP requirement for BITS downloads](https://msdn.microsoft.com/en-us/library/windows/desktop/aa362846(v=vs.85).aspx).

Well, it turns out that GitHub download URLs redirect to Amazon S3 URLs. For instance:

[https://github.com/Microsoft/MIMWAL/releases/download/v2.17.0414.0/MIMWAL-2.17.0414.0.zip](https://github.com/Microsoft/MIMWAL/releases/download/v2.17.0414.0/MIMWAL-2.17.0414.0.zip)  
**302 Found**  
– REDIRECT –\>  
[https://github-production-release-asset-2e65be.s3.amazonaws.com/47265095/3c304c70-20ff-11e7-92c1-e2bb3d070b40?X-Amz-Algorithm=AWS4-HMAC-SHA256&amp;X-Amz-Credential=AKIAIWNJYAX4CSVEH53A%2F20180112%2Fus-east-1%2Fs3%2Faws4\_request&amp;X-Amz-Date=20180112T222609Z&amp;X-Amz-Expires=300&amp;X-Amz-Signature=5e5b88fbca6007f1f4faf09f9681a2f157ffa096299b27a70f1482da1584d64a&amp;X-Amz-SignedHeaders=host&amp;actor\_id=0&amp;response-content-disposition=attachment%3B%20filename%3DMIMWAL-2.17.0414.0.zip&amp;response-content-type=application%2Foctet-stream](https://github-production-release-asset-2e65be.s3.amazonaws.com/47265095/3c304c70-20ff-11e7-92c1-e2bb3d070b40?X-Amz-Algorithm=AWS4-HMAC-SHA256&amp;X-Amz-Credential=AKIAIWNJYAX4CSVEH53A%2F20180112%2Fus-east-1%2Fs3%2Faws4_request&amp;X-Amz-Date=20180112T222609Z&amp;X-Amz-Expires=300&amp;X-Amz-Signature=5e5b88fbca6007f1f4faf09f9681a2f157ffa096299b27a70f1482da1584d64a&amp;X-Amz-SignedHeaders=host&amp;actor_id=0&amp;response-content-disposition=attachment%3B%20filename%3DMIMWAL-2.17.0414.0.zip&amp;response-content-type=application%2Foctet-stream)  
**200 OK**

Unfortunately, Amazon S3 uses signed URLs, so the same signed URL can’t be used for both HEAD and GET because the request method is used to compute the signature. HEAD and GET will have different signatures (see [this](https://stackoverflow.com/questions/20579846/in-amazon-s3-what-permissions-do-i-need-to-get-head-on-an-object), [this](https://stackoverflow.com/questions/2213941/background-intelligent-transfer-service-and-amazon-s3)and [this](https://groups.google.com/forum/m/#!topic/jets3t-users/E9SgfjpC6bc)). Thus, BITS’ initial HEAD request is what’s causing the HTTP 403 failure.

**WORKAROUND**  
BITS bypasses the HTTP HEAD request phase, issuing an HTTP GET request right away, if either of the following conditions is true:

1. The BITS job is configured with the [BITS\_JOB\_PROPERTY\_DYNAMIC\_CONTENT](https://msdn.microsoft.com/en-us/library/windows/desktop/hh446783(v=vs.85).aspx) flag.
2. BranchCache is disabled **AND** the BITS job contains a single file (always the case for [Start-BitsTransfer](https://technet.microsoft.com/en-us/library/dd819420.aspx)).

Workaround (1) is the most appropriate, since it doesn’t affect other BITS transfers in the system. Sadly, the BITS\_JOB\_PROPERTY\_DYNAMIC\_CONTENT flag isn’t currently exposed by BITS’ PowerShell cmdlets. However, the [BITSAdmin Tool](https://msdn.microsoft.com/en-us/library/windows/desktop/aa362813(v=vs.85).aspx) does expose it (via /dynamic). Example BITSAdmin command that works fine:

```
bitsadmin /transfer mydownload /dynamic /download /priority FOREGROUND https://github.com/Microsoft/MIMWAL/releases/download/v2.17.0414.0/MIMWAL-2.17.0414.0.zip C:\foo.zip
```

For workaround (2), BranchCache can be disabled through BITS’ [DisableBranchCache](https://msdn.microsoft.com/en-us/library/windows/desktop/aa362844(v=vs.85).aspx)group policy. You’ll need to do “gpupdate” from an elevated command prompt after making any Group Policy changes, or it will take ~90 minutes for the changes to take effect.

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:36pm UTC](https://forums.powershell.org/t/bits-transfer-with-github/8652/5 "2024-05-16T20:36:52Z")

</div>

Closed on May 16, 2024, 8:36pm UTC


