title: Downloading Xcode with wget or curl
body: <p>I am trying to download Xcode from the Apple Developer site using just wget or curl.  I think I am successfully storing the cookie I need to download the .dmg file, but I am not completely sure.</p>
  
  <p>When I run this command:</p>
  
  <pre><code>wget \  
     --post-data="theAccountName=USERNAME&amp;theAccountPW=PASSWORD" \  
     --cookies=on \  
     --keep-session-cookies \  
     --save-cookies=cookies.txt \        
     -O - \  
     https://developer.apple.com/ios/download.action?path=/ios/ios_sdk_4.1__final/xcode_3.2.4_and_ios_sdk_4.1.dmg &gt; /dev/null
  </code></pre>
  
  <p>A file called <code>cookies.txt</code> is created and contains something like this:</p>
  
  <pre><code>developer.apple.com FALSE / FALSE 0 XXXXXXXXXXXXXXXX  XXXXXXXXXXXX
  developer.apple.com FALSE / FALSE 0 developer.sessionToken
  </code></pre>
  
  <p>I'm not completely certain, but I think there should be more to it than that (specifically, an alphanumeric string after <code>sessionToken</code>).</p>
  
  <p>When I try to do the same thing with curl using this:</p>
  
  <pre><code>curl \  
     -d "theAccountName=USERNAME&amp;theAccountPW=PASSWORD" \
     -c xcode-cookie \ 
     -A "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1" \
     https://developer.apple.com/ios/download.action?path=/ios/ios_sdk_4.1__final/xcode_3.2.4_and_ios_sdk_4.1.dmg
  </code></pre>
  
  <p>I get a file called <code>xcode-cookie</code> that contains the same information as the <code>cookies.txt</code> file wget gives me, except that the lines are reversed.</p>
  
  <p>I then tried to download the .dmg file.</p>
  
  <p>Using wget:</p>
  
  <pre><code>wget \
     --cookies=on \
     --load-cookies=cookies.txt \
     --keep-session-cookies \
     http://developer.apple.com/ios/download.action?path=/ios/ios_sdk_4.1__final/xcode_3.2.4_and_ios_sdk_4.1.dmg
  </code></pre>
  
  <p>This gives me a file called <code>login?appIdKey=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX&amp;path=%2F%2Fios%2Fdownload.action?path=%2Fios%2Fios_sdk_4.1__final%2Fxcode_3.2.4_and_ios_sdk_4.1.dmg
  </code>, which is just an HTML page containing the login form for the developer site.</p>
  
  <p>Using curl:</p>
  
  <pre><code>curl \
     -b xcode-cookie \
     -c xcode-cookie \
     -O -v \
     -A "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1" \
     https://developer.apple.com/ios/download.action?path=/ios/ios_sdk_4.1__final/xcode_3.2.4_and_ios_sdk_4.1.dmg
  </code></pre>
  
  <p>Which prints basically the same thing as wget (minus the HTML).</p>
  
  <p>I want to say it has to do with the sessionToken not being in the cookie, but like I said before I am not sure.  I even tried exporting the cookies from my browser and following the instructions in the blog post I linked below and several other sites I found while searching for help.</p>
  
  <p>I must be doing something wrong, unless Apple has changed something since Oct. 10 <a href="http://greendesignhq.com/blog/2010/10/downloading-xcode-builds-with-wget-or-curl/" rel="noreferrer">because this guy seems to be to do something right</a>.</p>
  
  <p>Thanks in advance!</p>