Use curl to download a file from sourceforge (mirror)

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 “”. If you just use “curl -O URL” nothing happens. Adding the option “-v” some more output is shown:

* About to connect() to port 80 (#0)
*   Trying connected
* Connected to ( 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:
> 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:
< 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 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

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.

One thought on “Use curl to download a file from sourceforge (mirror)

Leave a Reply

Your email address will not be published. Required fields are marked *