2016-11-01 341 views
4

我在写一个脚本,需要从sourceforge下载一个发布文件。如何获得良好的链接?如何使用wget从SourceForge下载文件?

2013年在这里给出了同样的问题和答案,但它不再工作。 https://unix.stackexchange.com/questions/86971/how-do-i-download-from-sourceforge-with-wget

$ wget 'http://downloads.sourceforge.net/project/romfs/genromfs/0.5.2/genromfs-0.5.2.tar.gz' 
Saving to: ‘download?use_mirror=vorboss.html’ 

更新:日志以下@ vookimedlo的回答是:

$ ls -ld $(which wget) 
lrwxr-xr-x 1 david admin 30 Mar 29 16:17 /usr/local/bin/wget -> ../Cellar/wget/1.19.1/bin/wget 

$ wget --version 
GNU Wget 1.19.1 built on darwin16.4.0. 

-cares +digest -gpgme +https +ipv6 -iri +large-file -metalink -nls 
+ntlm +opie -psl +ssl/openssl 

Wgetrc: 
    /Users/david/.wgetrc (user) 
    /usr/local/etc/wgetrc (system) 
Compile: 
    clang -DHAVE_CONFIG_H -DSYSTEM_WGETRC="/usr/local/etc/wgetrc" 
    -DLOCALEDIR="/usr/local/Cellar/wget/1.19.1/share/locale" -I. 
    -I../lib -I../lib -I/usr/local/opt/openssl/include -DNDEBUG 
Link: 
    clang -DNDEBUG -liconv -L/usr/local/opt/openssl/lib -lssl -lcrypto 
    -ldl -lz ftp-opie.o openssl.o http-ntlm.o ../lib/libgnu.a 


$ wget --content-disposition -c https://sourceforge.net/projects/freetype/files/freetype2/2.8/freetype-2.8.tar.bz2 
--2017-07-25 10:55:27-- https://sourceforge.net/projects/freetype/files/freetype2/2.8/freetype-2.8.tar.bz2 
Resolving sourceforge.net... 216.34.181.60 
Connecting to sourceforge.net|216.34.181.60|:443... connected. 
HTTP request sent, awaiting response... 
    HTTP/1.1 302 Found 
    Server: nginx 
    Date: Tue, 25 Jul 2017 08:55:28 GMT 
    Content-Type: text/html; charset=UTF-8 
    Content-Length: 365 
    Connection: close 
    Pragma: no-cache 
    Cache-Control: no-cache 
    X-UA-Compatible: IE=edge,chrome=1 
    X-Frame-Options: SAMEORIGIN 
    Content-Security-Policy: upgrade-insecure-requests 
    Set-Cookie: VISITOR=2b8474db-e3d7-4710-8a3d-974b86ef1b5a; expires="Fri, 23-Jul-2027 08:55:28 GMT"; httponly; Max-Age=315360000; Path=/ 
    Set-cookie: sourceforge=bcda7ec9e4ed439a64c5e64e590620b984ed89bcgAJ9cQEoVQVwcmVmc3ECfXEDVQ5fYWNjZXNzZWRfdGltZXEER0HWXcHgBmPgVQNrZXlxBVUkMmI4NDc0ZGItZTNkNy00NzEwLThhM2QtOTc0Yjg2ZWYxYjVhcQZVDl9jcmVhdGlvbl90aW1lcQdHQdZdweAGY9xVA19pZHEIVSA0MzRjODBmYjk0NjM0ZGNmYjU4Y2JhYWIxODdkMjVkN3EJdS4=; expires=Tue, 19-Jan-2038 03:14:07 GMT; httponly; Path=/; secure 
    Location: https://sourceforge.net/projects/freetype/files/freetype2/2.8/freetype-2.8.tar.bz2/download 
    X-Content-Type-Options: nosniff 
    Strict-Transport-Security: max-age=31536000 
Location: https://sourceforge.net/projects/freetype/files/freetype2/2.8/freetype-2.8.tar.bz2/download [following] 
--2017-07-25 10:55:28-- https://sourceforge.net/projects/freetype/files/freetype2/2.8/freetype-2.8.tar.bz2/download 
Connecting to sourceforge.net|216.34.181.60|:443... connected. 
HTTP request sent, awaiting response... 
    HTTP/1.1 200 OK 
    Server: nginx 
    Date: Tue, 25 Jul 2017 08:55:28 GMT 
    Content-Type: text/html; charset=utf-8 
    Content-Length: 128476 
    Connection: close 
    Pragma: no-cache 
    Cache-Control: no-cache 
    X-UA-Compatible: IE=edge,chrome=1 
    X-Frame-Options: SAMEORIGIN 
    Content-Security-Policy: upgrade-insecure-requests 
    Set-Cookie: VISITOR=2b8474db-e3d7-4710-8a3d-974b86ef1b5a; expires="Fri, 23-Jul-2027 08:55:28 GMT"; httponly; Max-Age=315360000; Path=/ 
    Set-cookie: sourceforge=797e45184f27a13d79e45d16b390a5e0bc9ef06dgAJ9cQEoVQhfZXhwaXJlc3ECY2RhdGV0aW1lCmRhdGV0aW1lCnEDVQoH9gETAw4HAAAAhVJxBFUDX2lkcQVVIDQzNGM4MGZiOTQ2MzRkY2ZiNThjYmFhYjE4N2QyNWQ3cQZVBmRsaGlzdHEHXXEIfXEJKFUHcmVsZWFzZXEKfXELKFUEZGF0ZXEMaANVCgfhBQ0KNwAAAACFUnENVQpzZl9maWxlX2lkcQ5KtGSWAVUIZmlsZW5hbWVxD1gjAAAAL2ZyZWV0eXBlMi8yLjgvZnJlZXR5cGUtMi44LnRhci5iejJxEHVVB3Byb2plY3RxEX1xEihVCXNob3J0bmFtZXETWAgAAABmcmVldHlwZXEUVQVzZl9pZHEVTVUMVQRuYW1lcRZYFAAAAFRoZSBGcmVlVHlwZSBQcm9qZWN0cRd1dWFVA2tleXEYVSQyYjg0NzRkYi1lM2Q3LTQ3MTAtOGEzZC05NzRiODZlZjFiNWFxGVUKY3VycmVudF9vc3EaXXEbKFUFd2luMzJxHFUHV2luZG93c3EdZVUFcHJlZnNxHn1xH1UOX2FjY2Vzc2VkX3RpbWVxIEdB1l3B4C2D8VUOX2NyZWF0aW9uX3RpbWVxIUdB1l3B4AZj3HUu; expires=Tue, 19-Jan-2038 03:14:07 GMT; httponly; Path=/; secure 
    X-Content-Type-Options: nosniff 
    Strict-Transport-Security: max-age=31536000 
Length: 128476 (125K) [text/html] 
Last-modified header missing -- time-stamps turned off. 
--2017-07-25 10:55:28-- https://sourceforge.net/projects/freetype/files/freetype2/2.8/freetype-2.8.tar.bz2/download 
Connecting to sourceforge.net|216.34.181.60|:443... connected. 
HTTP request sent, awaiting response... 
    HTTP/1.1 200 OK 
    Server: nginx 
    Date: Tue, 25 Jul 2017 08:55:29 GMT 
    Content-Type: text/html; charset=utf-8 
    Content-Length: 143733 
    Connection: close 
    Pragma: no-cache 
    Cache-Control: no-cache 
    X-UA-Compatible: IE=edge,chrome=1 
    X-Frame-Options: SAMEORIGIN 
    Content-Security-Policy: upgrade-insecure-requests 
    Set-Cookie: VISITOR=2b8474db-e3d7-4710-8a3d-974b86ef1b5a; expires="Fri, 23-Jul-2027 08:55:29 GMT"; httponly; Max-Age=315360000; Path=/ 
    Set-cookie: sourceforge=b5bd929d9431625f7b220b04e97d1949367d4ed4gAJ9cQEoVQhfZXhwaXJlc3ECY2RhdGV0aW1lCmRhdGV0aW1lCnEDVQoH9gETAw4HAAAAhVJxBFUDX2lkcQVVIDQzNGM4MGZiOTQ2MzRkY2ZiNThjYmFhYjE4N2QyNWQ3cQZVBmRsaGlzdHEHXXEIfXEJKFUHcmVsZWFzZX1xCihVBGRhdGVoA1UKB+EFDQo3AAAAAIVScQtVCnNmX2ZpbGVfaWRKtGSWAVUIZmlsZW5hbWVYIwAAAC9mcmVldHlwZTIvMi44L2ZyZWV0eXBlLTIuOC50YXIuYnoydVUHcHJvamVjdH1xDChVCXNob3J0bmFtZVgIAAAAZnJlZXR5cGVVBXNmX2lkTVUMVQRuYW1lWBQAAABUaGUgRnJlZVR5cGUgUHJvamVjdHV1YVUDa2V5cQ1VJDJiODQ3NGRiLWUzZDctNDcxMC04YTNkLTk3NGI4NmVmMWI1YXEOVQpjdXJyZW50X29zcQ9dcRAoVQV3aW4zMnERVQdXaW5kb3dzcRJlVQVwcmVmc3ETfXEUVQ5fYWNjZXNzZWRfdGltZXEVR0HWXcHgU/ahVQ5fY3JlYXRpb25fdGltZXEWR0HWXcHgBmPcdS4=; expires=Tue, 19-Jan-2038 03:14:07 GMT; httponly; Path=/; secure 
    X-Content-Type-Options: nosniff 
    Strict-Transport-Security: max-age=31536000 
Length: 143733 (140K) [text/html] 
Saving to: ‘download.html’ 

download.html          100%[============================================================================================================>] 140.36K 338KB/s in 0.4s 

2017-07-25 10:55:29 (338 KB/s) - ‘download.html’ saved [143733/143733] 

回答

2

你可以wget的使用只有当你细,您将使用一个实验性功能,这是必需的"--content-disposition"选项。

wget --content-disposition -c https://sourceforge.net/projects/freetype/files/freetype2/2.8/freetype-2.8.tar.bz2 

所有重定向都是自动处理的,请参见下面的输出。

--2017-07-22 22:26:05-- https://sourceforge.net/projects/freetype/files/freetype2/2.8/freetype-2.8.tar.bz2 
Resolving sourceforge.net... 216.34.181.60 
Connecting to sourceforge.net|216.34.181.60|:443... connected. 
HTTP request sent, awaiting response... 302 Found 
Location: https://sourceforge.net/projects/freetype/files/freetype2/2.8/freetype-2.8.tar.bz2/download [following] 
--2017-07-22 22:26:06-- https://sourceforge.net/projects/freetype/files/freetype2/2.8/freetype-2.8.tar.bz2/download 
Connecting to sourceforge.net|216.34.181.60|:443... connected. 
HTTP request sent, awaiting response... 302 Found 
Location: https://downloads.sourceforge.net/project/freetype/freetype2/2.8/freetype-2.8.tar.bz2?r=&ts=1500755167&use_mirror=kent [following] 
--2017-07-22 22:26:07-- https://downloads.sourceforge.net/project/freetype/freetype2/2.8/freetype-2.8.tar.bz2?r=&ts=1500755167&use_mirror=kent 
Resolving downloads.sourceforge.net... 216.34.181.59 
Connecting to downloads.sourceforge.net|216.34.181.59|:443... connected. 
HTTP request sent, awaiting response... 302 Found 
Location: https://kent.dl.sourceforge.net/project/freetype/freetype2/2.8/freetype-2.8.tar.bz2 [following] 
--2017-07-22 22:26:08-- https://kent.dl.sourceforge.net/project/freetype/freetype2/2.8/freetype-2.8.tar.bz2 
Resolving kent.dl.sourceforge.net... 212.219.56.185 
Connecting to kent.dl.sourceforge.net|212.219.56.185|:443... connected. 
HTTP request sent, awaiting response... 200 OK 
Length: 1873526 (1.8M) [application/octet-stream] 
--2017-07-22 22:26:08-- https://kent.dl.sourceforge.net/project/freetype/freetype2/2.8/freetype-2.8.tar.bz2 
Connecting to kent.dl.sourceforge.net|212.219.56.185|:443... connected. 
HTTP request sent, awaiting response... 200 OK 
Length: 1873526 (1.8M) [application/octet-stream] 
Saving to: ‘freetype-2.8.tar.bz2’ 

freetype-2.8.tar.bz2        100%[==========================================================================================================>] 1.79M 5.60MB/s in 0.3s 

2017-07-22 22:26:08 (5.60 MB/s) - ‘freetype-2.8.tar.bz2’ saved [1873526/1873526] 

更新,以提供更多的细节

➜ ~ ls -ld $(which wget) 
lrwxr-xr-x 1 duda admin 32 4 črv 19:44 /usr/local/bin/wget -> ../Cellar/wget/1.19.1_1/bin/wget 
➜ ~ wget --version 
GNU Wget 1.19.1 built on darwin16.6.0. 

-cares +digest -gpgme +https +ipv6 -iri +large-file -metalink -nls 
+ntlm +opie -psl +ssl/openssl 

Wgetrc: 
    /usr/local/etc/wgetrc (system) 
Compile: 
    clang -DHAVE_CONFIG_H -DSYSTEM_WGETRC="/usr/local/etc/wgetrc" 
    -DLOCALEDIR="/usr/local/Cellar/wget/1.19.1_1/share/locale" -I. 
    -I../lib -I../lib -I/usr/local/opt/[email protected]/include -DNDEBUG 
Link: 
    clang -DNDEBUG -liconv -L/usr/local/opt/[email protected]/lib -lssl 
    -lcrypto -ldl -lz ftp-opie.o openssl.o http-ntlm.o ../lib/libgnu.a 

Copyright (C) 2015 Free Software Foundation, Inc. 
License GPLv3+: GNU GPL version 3 or later 
<http://www.gnu.org/licenses/gpl.html>. 
This is free software: you are free to change and redistribute it. 
There is NO WARRANTY, to the extent permitted by law. 

Originally written by Hrvoje Niksic <[email protected]>. 
Please send bug reports and questions to <[email protected]>. 
+0

在OSX执行此命令后,我得到的,而不是BZ2文件的文件“download.html”(这是一个HTML文件)。我的wget命令不会抱怨'--content-disposition'参数,所以我想它会接受它。任何想法为什么它不在我的电脑上工作? –

+0

它适用于我的MacOS。我使用自制软件的wget。 '➜〜wget --help' 'GNU Wget 1.19.1,一个非交互式网络检索器.' – vookimedlo

+0

我使用的是自制的wget 1.19.1。这很奇怪...我已经在我的问题中发布了我的日志。 –