{"id":205,"date":"2010-04-06T20:09:53","date_gmt":"2010-04-06T19:09:53","guid":{"rendered":"http:\/\/www.miscdebris.net\/blog\/?p=205"},"modified":"2010-04-06T20:10:12","modified_gmt":"2010-04-06T19:10:12","slug":"use-curl-to-download-a-file-from-sourceforge-mirror","status":"publish","type":"post","link":"https:\/\/www.miscdebris.net\/blog\/2010\/04\/06\/use-curl-to-download-a-file-from-sourceforge-mirror\/","title":{"rendered":"Use curl to download a file from sourceforge (mirror)"},"content":{"rendered":"<p>Sometimes one wants to download a source package or similar from sourceforge with curl and not with the browser, e.g. in a script where one wants to download a package automatically. It turns out, that due the latest changes in the download system of sourceforge this is not straightforward.<!--more--><\/p>\n<p>Assume you want to download the binutils binary package from the <a href=\"http:\/\/www.mingw.org\" target=\"_blank\">MinGW project<\/a>. If you go to the <a href=\"http:\/\/sourceforge.net\/projects\/mingw\/files\/GNU%20Binutils\/binutils-2.20.1\/binutils-2.20.1-2-mingw32-bin.tar.gz\/download\" target=\"_blank\">download site of binutils<\/a> and click on &#8220;direct link&#8221; you get &#8220;http:\/\/downloads.sourceforge.net\/project\/mingw\/GNU%20Binutils\/binutils-2.20.1\/binutils-2.20.1-2-mingw32-bin.tar.gz&#8221;. If you just use &#8220;curl -O URL&#8221; nothing happens. Adding the option &#8220;-v&#8221; some more output is shown:<\/p>\n<pre>* About to connect() to downloads.sourceforge.net port 80 (#0)\r\n*   Trying 216.34.181.59... connected\r\n* Connected to downloads.sourceforge.net (216.34.181.59) port 80 (#0)\r\n&gt; GET \/project\/mingw\/GNU%20Binutils\/binutils-2.20.1\/binutils-2.20.1-2-mingw32-bin.tar.gz HTTP\/1.1\r\n&gt; User-Agent: curl\/7.16.4 (i386-apple-darwin9.0) libcurl\/7.16.4 OpenSSL\/0.9.7l zlib\/1.2.3\r\n&gt; Host: downloads.sourceforge.net\r\n&gt; Accept: *\/*\r\n&gt;\r\n&lt; HTTP\/1.1 302 Found\r\n&lt; X-Powered-By: PHP\/5.2.9\r\n&lt; Content-Disposition: attachment; filename=\"binutils-2.20.1-2-mingw32-bin.tar.gz\"\r\n&lt; Location: http:\/\/surfnet.dl.sourceforge.net\/project\/mingw\/GNU%20Binutils\/binutils-2.20.1\/binutils-2.20.1-2-mingw32-bin.tar.gz\r\n&lt; Content-type: text\/html\r\n&lt; Content-Length: 0\r\n&lt; Date: Tue, 06 Apr 2010 18:50:34 GMT\r\n&lt; Server: lighttpd\/1.4.26\r\n&lt;\r\n* Connection #0 to host downloads.sourceforge.net left intact\r\n* Closing connection #0<\/pre>\n<p>Sourceforge redirects to a mirror server, but curl doesn&#8217;t follow it. Fortunately the &#8220;-L&#8221; option tells curl to follow this redirection. So<\/p>\n<pre>curl -L -O http:\/\/downloads.sourceforge.net\/project\/mingw\/GNU%20Binutils\/binutils-2.20.1\/binutils-2.20.1-2-mingw32-bin.tar.gz<\/pre>\n<p>works. This <a href=\"http:\/\/sourceforge.net\/apps\/trac\/sourceforge\/ticket\/7375\" target=\"_blank\">sourceforge trac ticket<\/a> provided the information. Additionally it&#8217;s possible to shorten the URL a bit. Instead of the long URL above you could also use:<\/p>\n<pre>http:\/\/downloads.sourceforge.net\/sourceforge\/mingw\/binutils-2.20.1-2-mingw32-bin.tar.gz<\/pre>\n<p>Ok, it&#8217;s not that much shorter but still. I&#8217;m not sure if this always works, at least for MinGW packages it does.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Sometimes one wants to download a source package or similar from sourceforge with curl and not with the browser, e.g. in a script where one wants to download a package automatically. It turns out, that due the latest changes in the download system of sourceforge this is not straightforward.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false},"version":2}},"categories":[30,9,10],"tags":[],"class_list":["post-205","post","type-post","status-publish","format-standard","hentry","category-development","category-linux","category-macosx"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p6pnj-3j","_links":{"self":[{"href":"https:\/\/www.miscdebris.net\/blog\/wp-json\/wp\/v2\/posts\/205"}],"collection":[{"href":"https:\/\/www.miscdebris.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.miscdebris.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.miscdebris.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.miscdebris.net\/blog\/wp-json\/wp\/v2\/comments?post=205"}],"version-history":[{"count":12,"href":"https:\/\/www.miscdebris.net\/blog\/wp-json\/wp\/v2\/posts\/205\/revisions"}],"predecessor-version":[{"id":246,"href":"https:\/\/www.miscdebris.net\/blog\/wp-json\/wp\/v2\/posts\/205\/revisions\/246"}],"wp:attachment":[{"href":"https:\/\/www.miscdebris.net\/blog\/wp-json\/wp\/v2\/media?parent=205"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.miscdebris.net\/blog\/wp-json\/wp\/v2\/categories?post=205"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.miscdebris.net\/blog\/wp-json\/wp\/v2\/tags?post=205"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}