Skip to content

Instantly share code, notes, and snippets.

@iandundas
Created February 21, 2017 09:02
Show Gist options
  • Save iandundas/fabe07455e5216442a421922361f698c to your computer and use it in GitHub Desktop.
Save iandundas/fabe07455e5216442a421922361f698c to your computer and use it in GitHub Desktop.
Script for reliably downloading binaries (e.g. Xcode) from Apple's CDN
#!/usr/bin/env ruby
print "What is the URL of your Apple Downloads resource?\nURL:"
url = gets.strip
print "What is the ADCDownloadAuth cookie token:\nADCDownloadAuth: "
token = gets.strip
command = "aria2c --header \"Host: adcdownload.apple.com\" --header \"Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\" --header \"Upgrade-Insecure-Requests: 1\" --header \"Cookie: ADCDownloadAuth=#{token}\" --header \"User-Agent: Mozilla/5.0 (iPhone; CPU iPhone OS 10_1 like Mac OS X) AppleWebKit/602.2.14 (KHTML, like Gecko) Version/10.0 Mobile/14B72 Safari/602.1\" --header \"Accept-Language: en-us\" -x 16 -s 16 #{url} -d ~/Downloads"
exec(command)
@n0an
Copy link

n0an commented Jun 4, 2019

what is ADCDownloadAuth ? how to get it?

@iandundas
Copy link
Author

@lstomberg
Copy link

This works great!!

@amoghpalnitkar
Copy link

I think this no longer works. It gives me a 403 even after providing a valid cookie. Maybe apple has changed the authentication? God knows why.

@DrozNF
Copy link

DrozNF commented Nov 8, 2019

I too am getting the 403...

@thuss
Copy link

thuss commented Nov 22, 2019

It's working for me... I followed the instructions in this fork and the script above works fine: https://gist.github.com/manishpathak99/2a18fce18493f460fe80f2bd542a8560

@adauguet
Copy link

I had a 403, but managed to make it work by replacing https by http.

@vineetchoudhary
Copy link

I've created a macOS tool that you can use to download Xcode and other tools from developer.apple.com with up to 16 times faster (using the multi-connection download). Also, it has resume capability. You can use this if you want to avoid manual work.

https://github.com/vineetchoudhary/Downloader-for-Apple-Developers

Download

@iandundas
Copy link
Author

Nice!! I will check it next time I download

@zengadget
Copy link

Saves lifes!

@vmalyi
Copy link

vmalyi commented Mar 29, 2020

Thank you!

@eddy93
Copy link

eddy93 commented Jun 17, 2020

I’m getting this

`ERROR] CUID#7 - Download aborted. URI=https://developer.apple.com/download/more/
Exception: [AbstractCommand.cc:351] errorCode=22 URI=https://developer.apple.com/download/more/
-> [HttpSkipResponseCommand.cc:240] errorCode=22 The response status is not successful. status=403

`

@BrainCrumbz
Copy link

BrainCrumbz commented Jun 23, 2020

Hi all. Can anyone help us working through this?

As of today, for Xcode 11.5 and with redesigned Apple Download pages, we keep on receiving 403.

The cookie should be correct, we tried both straight from Developer Console, as well as with a Firefox Cookie Quick Manager extension, just to be sure: they report the same value, same characters.

The download URL, as of today, looks like (taken from https://xcodereleases.com/):
https://developer.apple.com/services-account/download?path=/Developer_Tools/Xcode_11.5/Xcode_11.5.xip
Not sure if that querystring parameter messes up things (unlikely).

We tried with just http: no luck. We also tried with a forked gist by @manishpathak99: https://gist.github.com/manishpathak99/2a18fce18493f460fe80f2bd542a8560. Same result (also, the script seems the same from a quick look). We also tried to structure the URL as posted in that forked gist (https://download.developer.apple.com/Developer_Tools/foo/bar.xip), again with no luck (actually this URL gives 403 in browser too).

@BrainCrumbz
Copy link

Ok, found issue. Cookie was ok. URL taken from xcodereleases.com apparently was not working for the script.

The right URL is the one taken from https://developer.apple.com/download/more/. It actually has the same structure as posted in the forked gist, so we made some errors before, while trying to make that URL up on our own.

@rraallvv
Copy link

rraallvv commented Jul 8, 2020

@khoahuynhdev
Copy link

This is great, thanks a lot.

@Ziplip
Copy link

Ziplip commented Feb 26, 2021

Perfect, thank you much! Another fast method I have discovered is to retrieve the xip from the developer site, using a Safari browser and my iPhone's Personal Hotspot over Bluetooth.

@darwingr
Copy link

darwingr commented Apr 27, 2021

#!/usr/bin/env ruby

print "What is the URL of your Apple Downloads resource?\nURL:"
url = gets.strip

print "What is the ADCDownloadAuth cookie token:\nADCDownloadAuth: "
token = gets.strip

command = <<~SHELL
aria2c \
  --header "Host: adcdownload.apple.com" \
  --header "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8" \
  --header "Upgrade-Insecure-Requests: 1" \
  --header "Cookie: ADCDownloadAuth=#{token}" \
  --header "User-Agent: Mozilla/5.0 (iPhone; CPU iPhone OS 10_1 like Mac OS X) AppleWebKit/602.2.14 (KHTML, like Gecko) Version/10.0 Mobile/14B72 Safari/602.1" \
  --header "Accept-Language: en-us" \
  --max-connection-per-server=16 \
  --split=16 \
  -d ~/Downloads \
  --continue=true \
  #{url}
SHELL

exec(command)

Changes

  1. Puts the shell command in a heredoc for readability.
  2. Used long argument on non-intuitive arguments...for understandability.
  3. Removed the escapes on the double-quotes within the command because it no longer seems necessary within a heredoc...so far so good.
  4. Added the continue argument, in case you want to pick up after a partial download via your browser.

Result

I can confirm, the above worked without modification.
After having downloaded 1/3rd of the way with Safari, I copied the partially downloaded Xcode_12.5.xip from the .download subfolder to the ~/Downloads folder a ran the above script. The download resumed without starting over. Completed download successfully passes integrity check.

@t1m9mofficial
Copy link

Still works! Thank you;

macOS Catalina Version 10.15.7
MacBook Pro (Retina, 13-inch, Mid 2014)

@suyogwani11
Copy link

suyogwani11 commented Dec 24, 2021

@BrainCrumbz trying to download using https://download.developer.apple.com/Developer_Tools/Xcode_13.2.1/Xcode_13.2.1.xip
Getting status=403. can you please post correct URL?

never-mind, https to http worked for me.

@ThePredators
Copy link

ThePredators commented Dec 24, 2021

There is a tool that work great without any pain to download xcode.

You can download, install & switch between different versions of installed xcode.

It's called xcodes - - > https://github.com/RobotsAndPencils/xcodes

@tobiasmuehl
Copy link

Alternatively, I found out that using a VPN can greatly increase the download speeds while using the regular App Store. Using Mullvad for this but other providers are probably similar

@shijiezhou1
Copy link

You solved my problem that I spent 3 years on finding the answer.

@deepumukundan
Copy link

FYI. The latest Apple developer portal (as of 2022-Jun-6th) does not seem to include the ADCDownloadAuth cookie.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment