Is there a way for downloading XCode using curl or wget?

EDIT: Why is the following curl snippet not working?

First, I login to Apple's site:

curl -d "theAccountName=USERNAME&theAccountPW=PASS" -c xcode-cookie 
-A "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv: Gecko/20061204 Firefox/" 

Then, I try to download the file:

curl -b xcode-cookie -c xcode-cookie -O -v -A 
"Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv: Gecko/20061204 Firefox/"

However I get a 403 Forbidden error:

* About to connect() to adcdownload.apple.com port 80 (#0)
*   Trying   % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0connected
* Connected to adcdownload.apple.com ( port 80 (#0)
> GET /ios/ios_sdk_4.0.2__final/xcode_3.2.3_and_ios_sdk_4.0.2.dmg HTTP/1.1
> User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv: Gecko/20061204 Firefox/
> Host: adcdownload.apple.com
> Accept: */*
> Cookie: myacinfo=foo; DefaultAppleID=bar; ds01=baz
< HTTP/1.1 403 Forbidden
< Server: Apache-Coyote/1.1
< X-Powered-By: Servlet 2.4; JBoss-4.0.5.GA (build: CVSTag=Branch_4_0 date=200610162339)/Tomcat-5.5
< no-cache: Cache-Control
< no-store: Cache-Control
< Content-Type: text/html;charset=ISO-8859-1
< Date: Mon, 30 Aug 2010 05:30:42 GMT
< Transfer-Encoding:  chunked
< Connection: keep-alive
< Connection: Transfer-Encoding
< Cache-Control: no-store
{ [data not shown]
100  1932    0  1932    0     0   7531      0 --:--:-- --:--:-- --:--:--  8548* Connection #0 to host adcdownload.apple.com left intact

* Closing connection #0

closed as too localized by Daniel Beck, studiohack Mar 24 '11 at 14:20

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center. If this question can be reworded to fit the rules in the help center, please edit the question.


Josh thinks too simple-mindedly. The URL to download Xcode is indeed http://developer.apple.com/iphone/download.action?path=%2Fios%2Fios_sdk_4.0.2__final%2Fxcode_3.2.3_and_ios_sdk_4.0.2.dmg

However, you must be authenticated to download the file.

Now both Wget and cURL support cookies, but I've never used cURL for downloads so here's a couple of lines using Wget to first authenticate into the developer site (storing the authentication cookies in a cookies.txt file), then another line to actually grab the download (recalling that same cookies.txt file):

wget --post-data="theAccountName=YOURUSERNAME&theAccountPW=YOURPASSWORD" --cookies=on --load-cookies=cookies.txt --keep-session-cookies --save-cookies=cookies.txt https://daw.apple.com/cgi-bin/WebObjects/DSAuthWeb.woa/67/wo/99OWdOWyhWA2pMdrPemdSw/
wget --cookies=on --load-cookies=cookies.txt --keep-session-cookies --save-cookies=cookies.txt http://developer.apple.com/iphone/download.action?path=%2Fios%2Fios_sdk_4.0.2__final%2Fxcode_3.2.3_and_ios_sdk_4.0.2.dmg

Be sure to change YOURUSERNAME and YOURPASSWORD to the appropriate values, and change the path to the cookies.txt file if so desired. Also, note the URL of the login form might change, so be sure to check the action attribute of the login form from your browser if this fails to work.

I tested this on my server, and the download took about 40 minutes. It worked a treat!

  • Sure, I didn't explicitly mention that, it was assumed if you need authentication you can use the options available for the tool. +1, nice that you pasted that code in for him. – Josh K Aug 25 '10 at 19:02
  • On here, people tend to expect to be shown some code. :) – purefusion Aug 25 '10 at 19:05
  • Thanks, but the problem is that OS X does not come bundled with wget and I need to use curl. Please see my updated post. I have accepted your solution but a curl solution will be highly appreciated. – Behrang Aug 30 '10 at 5:48

Single command, using stock Mac OS X 10.6.6 command line tools (bash, curl and sqlite3).

curl -b <(sqlite3 -separator $'\t' ~/Library/Application\ Support/Google/Chrome/Default/Cookies "select host_key, 'TRUE','/', 'FALSE', expires_utc, name, value from cookies where host_key like '%apple.com%'") http://adcdownload.apple.com/ios/ios_sdk_4.2__final/xcode_3.2.5_and_ios_sdk_4.2_final.dmg


  1. This uses a query of Google Chrome's sqlite cookie database.

  2. You need to login via Apple's Xcode developer page with the browser first so that the cookies get set.


  1. <() is bash's Process Substitution operator and does away with the instantly-stale temporary cookies file.

  2. If, like me, you are resuming a stalled browser download, and you have the file, use these arguments:

    -C - -o unconfirmed\ 21043.crdownload

Now that you have Xcode, you can install Homebrew, and then wget. ;)

  • 1
    Hehe. Of course, then he'd already have XCode and would no longer need wget to download it (save for perhaps future updates). I wasn't aware wget didn't come with OSX though. How'd I miss that? I guess I've never tried to use it on anything but my remote linux server. – purefusion Jan 21 '11 at 6:21

Of course, just copy the download link that you got from Apple.

  • 2
    It needs authentication. – Behrang Aug 25 '10 at 15:41
  • @bytecode: Hence the availability of --post-data and --cookie options for wget. You can even do those things in curl. – Josh K Aug 25 '10 at 19:01

Not the answer you're looking for? Browse other questions tagged or ask your own question.