使用 wget 或 curl 下载 Xcode
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4081568/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Downloading Xcode with wget or curl
提问by Joe
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.
我正在尝试仅使用 wget 或 curl 从 Apple Developer 站点下载 Xcode。我想我已经成功存储了下载 .dmg 文件所需的 cookie,但我不完全确定。
When I run this command:
当我运行此命令时:
wget \
--post-data="theAccountName=USERNAME&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 > /dev/null
A file called cookies.txt
is created and contains something like this:
一个名为的文件cookies.txt
被创建并包含如下内容:
developer.apple.com FALSE / FALSE 0 XXXXXXXXXXXXXXXX XXXXXXXXXXXX
developer.apple.com FALSE / FALSE 0 developer.sessionToken
I'm not completely certain, but I think there should be more to it than that (specifically, an alphanumeric string after sessionToken
).
我并不完全确定,但我认为应该有更多内容(特别是在 之后的字母数字字符串sessionToken
)。
When I try to do the same thing with curl using this:
当我尝试使用 curl 做同样的事情时:
curl \
-d "theAccountName=USERNAME&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
I get a file called xcode-cookie
that contains the same information as the cookies.txt
file wget gives me, except that the lines are reversed.
我得到一个名为的文件xcode-cookie
,其中包含与cookies.txt
wget 给我的文件相同的信息,只是行颠倒了。
I then tried to download the .dmg file.
然后我尝试下载 .dmg 文件。
Using wget:
使用 wget:
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
This gives me a file called login?appIdKey=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX&path=%2F%2Fios%2Fdownload.action?path=%2Fios%2Fios_sdk_4.1__final%2Fxcode_3.2.4_and_ios_sdk_4.1.dmg
, which is just an HTML page containing the login form for the developer site.
这给了我一个名为 的文件login?appIdKey=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX&path=%2F%2Fios%2Fdownload.action?path=%2Fios%2Fios_sdk_4.1__final%2Fxcode_3.2.4_and_ios_sdk_4.1.dmg
,它只是一个包含开发人员站点登录表单的 HTML 页面。
Using curl:
使用卷曲:
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
Which prints basically the same thing as wget (minus the HTML).
它打印的内容与 wget 基本相同(减去 HTML)。
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.
我想说这与 sessionToken 不在 cookie 中有关,但就像我之前说的那样,我不确定。我什至尝试从我的浏览器导出 cookie,并按照我在下面链接的博客文章和我在搜索帮助时找到的其他几个站点中的说明进行操作。
I must be doing something wrong, unless Apple has changed something since Oct. 10 because this guy seems to be to do something right.
我一定是做错了什么,除非苹果自 10 月 10 日以来做出了一些改变,因为这家伙似乎做对了。
Thanks in advance!
提前致谢!
回答by petert
For Chrome,
对于铬,
- Install cookies.txt Chrome extension
- Login to Apple Developer site and get the url for downloading
- Run cookies.txt extension and download cookies.txt file
From the cookies.txt download directory, load cookies into wget and start resumable download. For example, to download Xcode_7.dmg, you would run:
wget --load-cookies=cookies.txt -c http://adcdownload.apple.com/Developer_Tools/Xcode_7/Xcode_7.dmg
- 安装cookies.txt Chrome 扩展
- 登录苹果开发者网站,获取下载地址
- 运行 cookies.txt 扩展并下载 cookies.txt 文件
从 cookies.txt 下载目录,将 cookies 加载到 wget 并开始可恢复下载。例如,要下载 Xcode_7.dmg,您需要运行:
wget --load-cookies=cookies.txt -c http://adcdownload.apple.com/Developer_Tools/Xcode_7/Xcode_7.dmg
回答by Ethan
Maybe this is the easiest way to use curl:
也许这是使用 curl 的最简单方法:
- open
Google Chrome.app
; - goto site
developer.apple.com
; - press
CMD
+SHIFT
+J
or click top-rightMenu
icon ->Tools
->Developer Tools
; - click
Network
panel; - now click
Xcode
download link at apple.com; - you will see one or more request records in the
Network
panel; - right click the latest record, then click
Copy as cURL
;
- 打开
Google Chrome.app
; - 转到网站
developer.apple.com
; - 按
CMD
+SHIFT
+J
或单击右上角的Menu
图标 ->Tools
->Developer Tools
; - 点击
Network
面板; - 现在点击
Xcode
apple.com 上的下载链接; - 您将在
Network
面板中看到一个或多个请求记录; - 右键单击最新记录,然后单击
Copy as cURL
;
Now, you got the curl command for this download link with cookies and other http-requeset-fields, just paste to your terminal and add -o xxx.dmg
at the end.
现在,您获得了带有 cookie 和其他 http-requeset-fields 的此下载链接的 curl 命令,只需粘贴到您的终端并添加-o xxx.dmg
到最后即可。
回答by Noah Spurrier
Here is a script that uses curl instead of wget, so it will work on a stock Mac. All you need to set is the path to the xcode DMG file. The script will ask you for your username and password and it will figure out the ACTION and WOSID values for you.
这是一个使用 curl 而不是 wget 的脚本,因此它可以在普通 Mac 上运行。您需要设置的只是 xcode DMG 文件的路径。该脚本将询问您的用户名和密码,并为您找出 ACTION 和 WOSID 值。
#!/bin/sh # Change this line to the URI path of the xcode DMG file. XCODE_PATH="/ios/ios_sdk_4.2__final/xcode_3.2.5_and_ios_sdk_4.2_final.dmg" echo "Enter your Apple Dev Center username." read -p "> " USERNAME echo "Enter your Apple Dev Center password." read -p "> " PASSWORD curl \ -L -s -k \ --cookie-jar cookies \ -A "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.1) Gecko/20090624 Firefox/3.5" \ https://developer.apple.com/devcenter/ios/login.action \ -o login.html ACTION=$(sed -n 's/.*action="\(.*\)".*//p' login.html) WOSID=$(sed -n 's/.*wosid" value="\(.*\)".*//p' login.html) echo "action=${ACTION}" echo "wosid=${WOSID}" curl \ -s -k --cookie-jar cookies --cookie cookies \ -A "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.1) Gecko/20090624 Firefox/3.5" \ -e ";auto" "https://daw.apple.com${ACTION}?theAccountName=${USERNAME}&theAccountPW=${PASSWORD}&theAuxValue=&wosid=${WOSID}&1.Continue.x=0&1.Continue.y=0" \ > /dev/null curl \ -L --cookie-jar cookies --cookie cookies \ -A "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.1) Gecko/20090624 Firefox/3.5" \ -O https://developer.apple.com/ios/download.action?path=${XCODE_PATH} rm login.html rm cookies
回答by Greg
I've just been down the same road after failing repeatedly to download the latest version of Xcode directly to my Mac dev machine. I also couldn't get Daniel's approach to work exactly as written.
在多次将最新版本的 Xcode 直接下载到我的 Mac 开发机器上失败后,我刚刚走上了同样的道路。我也无法完全按照丹尼尔的方式工作。
This is what did work for me:
这对我有用:
Used Firefox to log in to the iOS dev center
Used Cookie Exporter 1.5to save the cookies to a text file, say "cookies.txt"
FTP'd cookies.txt to a staging server of mine that has a nice fat pipe onto the Internet
Used wget from the staging server to download the file (about 5 minutes)
Used FTP to transfer the DMG file back to my dev machine (about 2 hours)
使用Firefox登录iOS开发中心
使用Cookie Exporter 1.5将 cookie 保存到文本文件中,例如“cookies.txt”
FTP'd cookies.txt 到我的一个临时服务器,它有一个很好的胖管道到互联网
使用来自临时服务器的 wget 下载文件(大约 5 分钟)
使用 FTP 将 DMG 文件传输回我的开发机器(大约 2 小时)
Here is the wget command line:
这是 wget 命令行:
wget --cookies=on --load-cookies=cookies.txt --keep-session-cookies --save-cookies=cookies.txt http://adcdownload.apple.com/ios/ios_sdk_4.1__final/xcode_3.2.4_and_ios_sdk_4.1.dmg
The trick here is to NOT use the download link from the page, but rather to start the download then use the context menu in the download list to "Copy Download Link".
这里的技巧是不使用页面上的下载链接,而是开始下载,然后使用下载列表中的上下文菜单“复制下载链接”。
回答by Ben Sinclair
Not optimal but works for me:
不是最佳的,但对我有用:
If you know direct URL for download (e.g. you started download) then you can log-in on developer portal and run the following JS in console:
如果您知道下载的直接 URL(例如您开始下载),那么您可以登录开发人员门户并在控制台中运行以下 JS:
copy('wget -c http://adcdownload.apple.com//Developer_Tools/xcode_6_beta_5_za4gu6/xcode_6_beta_5.dmg --header="Cookie:' + document.cookie + '"')
This will copy wget command in clipboard with all necessary cookies for wget to work. You can restart this command anytime to continue.
这将复制剪贴板中的 wget 命令以及 wget 工作所需的所有 cookie。您可以随时重新启动此命令以继续。
回答by Joe
So I've seemed to figure out the answer to my own question. Here's how you can download Xcode using curl.
所以我似乎找到了我自己问题的答案。以下是使用 curl 下载 Xcode 的方法。
First, run this:
首先,运行这个:
curl \
-L -s -k \
--cookie-jar cookies \
-A "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.1) Gecko/20090624 Firefox/3.5" \
https://developer.apple.com/devcenter/ios/login.action \
-o login.html
Open the login.html
file that's created and look for these 2 things:
打开login.html
创建的文件并查找以下两件事:
- The
action
attribute of the login form. It should be on/around line 54. - The
input
field namedwosid
. This should be on/around line 129.
action
登录表单的属性。它应该在第 54 行上/附近。input
名为的字段wosid
。这应该在第 129 行/附近。
Copy the value of the action
attribute as well as the value of the value
attribute of the input field. You'll need these for the next step.
复制action
属性值以及value
输入字段的属性值。您将需要这些用于下一步。
Here's the next curl command:
这是下一个 curl 命令:
curl \
-s -k --cookie-jar cookies --cookie cookies \
-A "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.1) Gecko/20090624 Firefox/3.5" \
-e ";auto" "https://daw.apple.com{ACTION}?theAccountName={USERNAME}&theAccountPW={PASSWORD}&theAuxValue=&wosid={WOSID}&1.Continue.x=0&1.Continue.y=0" \
> /dev/null
- Replace
{ACTION}
with the action value you saved - Replace
{USERNAME}
and{PASSWORD}
with your Apple Dev Center credentials - Replace
{WOSID}
with the wosid value you saved - Run the command
- 替换
{ACTION}
为您保存的操作值 - 用您的 Apple Dev Center 凭据替换
{USERNAME}
和{PASSWORD}
- 替换
{WOSID}
为您保存的 wosid 值 - 运行命令
You should now have the cookie that will allow you to download the .dmg file. If you haven't noticed by now, the cookie is stored in a file called cookies
.
您现在应该拥有允许您下载 .dmg 文件的 cookie。如果您现在还没有注意到,cookie 存储在一个名为cookies
.
Now just run this last curl command and the Xcode image should begin downloading:
现在只需运行最后一个 curl 命令,Xcode 图像就会开始下载:
curl \
-L --cookie-jar cookies --cookie cookies \
-A "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.1) Gecko/20090624 Firefox/3.5" \
-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
I've tried this on 2 different machines and works on both.
我已经在 2 台不同的机器上尝试过这个,并且在两台机器上都可以使用。
回答by denis
Here's a little bash script to wget Xcode :
这是一个用于 wget Xcode 的小 bash 脚本:
#!/bin/bash
export ID=YourAppleID
export PW=YourPW
[ -f cookies ] && rm cookies && touch cookies
2>Header \
wget \
-S \
-O R1 \
http://developer.apple.com/ios/download.action?path=/ios/ios_sdk_4.2__final/xcode_3.2.5_and_ios_sdk_4.2_final.dmg
tac Header | grep Location
LOCATION=$(grep Location Header | sed -E 's/^ *Location: ([^/]+:\/\/[^/]+)\/.*$//')
[ -z "$LOCATION" ] && { echo "Bad day for LOCATION...";exit;} || echo "LOCATION=$LOCATION"
rm Header
ACTION=$(grep action R1 | sed 's/^.*action="//;s/".*$//')
[ -z "$ACTION" ] && { echo "Bad day for ACTION...";exit;} || echo "ACTION=$ACTION"
POST=$( grep input R1 | sed 's/<input/\
<input/g' | grep input | sed 's/^.*name="//' | sed 's/".*value="/=/;s/".*$//' | sed '/=/!s/$/=/' | sed '/theAccountName/s/$/'$ID'/;/theAccountPW/s/$/'$PW'/' | sed '/=$/d' | sed -n '1h;1!H;${x;s/[[:space:]]/\&/g;p;}' | sed 's/$/\&1.Continue.x=0\&1.Continue.y=0/')
[ -z "$POST" ] && { echo "Bad day for POST...";exit;} || echo "POST=$POST"
2>Header \
wget \
-S \
--save-cookies cookies \
--keep-session-cookies \
-O R2 \
--post-data="$POST" \
$LOCATION/$ACTION
URL=$( grep -i REFRESH R2 | sed 's/^.*URL=//;s/".*$//' )
[ -z "$URL" ] && { echo "Bad day for URL...";exit;} || echo "URL=$URL"
wget \
-S \
--load-cookies cookies \
$URL &
sleep 1; rm R1 R2 Header cookies
Comments are the same as for joe's Solution - Thnx Joe ;o) The good idea is to start the traffic analysis from the download url of Xcode.
评论与 joe 的解决方案相同 - Thnx Joe ;o) 好主意是从 Xcode 的下载 url 开始流量分析。