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.
Assume you want to download the binutils binary package from the MinGW project. If you go to the download site of binutils and click on “direct link” you get “http://downloads.sourceforge.net/project/mingw/GNU%20Binutils/binutils-2.20.1/binutils-2.20.1-2-mingw32-bin.tar.gz”. If you just use “curl -O URL” nothing happens. Adding the option “-v” some more output is shown:
* About to connect() to downloads.sourceforge.net port 80 (#0) * Trying 22.214.171.124... connected * Connected to downloads.sourceforge.net (126.96.36.199) port 80 (#0) > GET /project/mingw/GNU%20Binutils/binutils-2.20.1/binutils-2.20.1-2-mingw32-bin.tar.gz HTTP/1.1 > User-Agent: curl/7.16.4 (i386-apple-darwin9.0) libcurl/7.16.4 OpenSSL/0.9.7l zlib/1.2.3 > Host: downloads.sourceforge.net > Accept: */* > < HTTP/1.1 302 Found < X-Powered-By: PHP/5.2.9 < Content-Disposition: attachment; filename="binutils-2.20.1-2-mingw32-bin.tar.gz" < Location: http://surfnet.dl.sourceforge.net/project/mingw/GNU%20Binutils/binutils-2.20.1/binutils-2.20.1-2-mingw32-bin.tar.gz < Content-type: text/html < Content-Length: 0 < Date: Tue, 06 Apr 2010 18:50:34 GMT < Server: lighttpd/1.4.26 < * Connection #0 to host downloads.sourceforge.net left intact * Closing connection #0
Sourceforge redirects to a mirror server, but curl doesn’t follow it. Fortunately the “-L” option tells curl to follow this redirection. So
curl -L -O http://downloads.sourceforge.net/project/mingw/GNU%20Binutils/binutils-2.20.1/binutils-2.20.1-2-mingw32-bin.tar.gz
works. This sourceforge trac ticket provided the information. Additionally it’s possible to shorten the URL a bit. Instead of the long URL above you could also use:
Ok, it’s not that much shorter but still. I’m not sure if this always works, at least for MinGW packages it does.