(I'm documenting this trick for myself to remember, but it can be useful for others…)
Apple, on its Apple Developer Connection site, has a bad habit of not providing small or separate SDK downloads for iOS or Mac OS X development. This means, for example, that I have to download a 4.3GB bundle for Xcode 4 and iOS SDK 4.3 to get one of those. Problem: I'm living on a small island where the local postal-and-telecommunications monopoly is better at finding ways to milk everybody to death rather than providing a fast, stable and affordable internet connection as part of its public service duties, so it's simply impossible to download gigabytes of data without being disconnected at least once. The fact is that I've never been able to download anything on ADC without fail.
Thanks to the Unix roots of Mac OS X, we have
curl to the rescue. Here's how to resume a failed download on ADC:
- Let's say you have started to download the file
xcode_4_and_ios_sdk_4.3__final.dmgbut the download has been interrupted. Usually, Safari will happily pretend that the download has completed, but the DMG archive won't load. If you check the file size, it's less than it should be.
- Check the Finder Info for that file and look in the More Info panel where it comes from. There will probably be several URLs (because of redirections), take the first one. For me it's
- Connect to ADC to reauthenticate
- In the web inspector on the ADC page, go to Storage then Cookies and note the ADCDownloadAuth cookie and its content. In curl parlance, this will translate into something like:
-b "ADCDownloadAuth=<cookie value>;"
- And finally, in Terminal — assuming you are in the same path as the download file, get there or give the full path to the
-o fileoption — both the
-C -and the
-o fileoptions will tell curl to resume the download exactly where it stopped, and the
--retry 100will automatically retry up to 100 times in case it fails again (so it'll work unattended):
curl -b "ADCDownloadAuth=<cookie value>;" -C - --retry 100 -o xcode_4_and_ios_sdk_4.3__final.dmg http://adcdownload.apple.com/Developer_Tools/xcode_4_and_ios_sdk_4.3__final/xcode_4_and_ios_sdk_4.3__final.dmg
Et voilà !
P.S. My CSS overflow rule cuts the long lines above so I've used a zero-width space to force line breaks, but you should get the gist.
P.S. 2: Added the
--retry 100 option to let curl automatically resume the download in case it fails again.
P.S. 3: Just found this script from Michael Tyson which automates all the manual steps above (won't retry automatically, though it's easy to modify it). Very handy!