Download file with url redirection
47,026
Use -L, --location
to follow redirects:
$ curl -L http://httpbin.org/redirect/1
Comments
-
edem over 3 years
I can download a file by url but when I try it from bash I get a html page instead of a file.
How to download file with url redirection (301 Moved Permanently) using curl, wget or something else?
UPD
Headers from the url request.
HTTP/1.1 301 Moved Permanently Date: Sat, 07 Dec 2013 10:15:28 GMT Server: Apache/2.2.22 (Ubuntu) X-Powered-By: PHP/5.3.10-1ubuntu3 Location: http://www.somesite.com/files/html/archive.html Vary: Accept-Encoding Content-Type: text/html X-Pad: avoid browser bug
-
slayedbylucifer over 10 years
wget --content-disposition <URL>
, Could you try this? -
edem over 10 yearsYes, I could. It doesn't work.
-
janos over 10 yearsWhat do you mean it doesn't work?
-
edem over 10 yearsI get the same result with this option.
-
Vijay Rajpurohit about 4 yearsis this problem solved ?
-
-
edem over 10 yearsGet the content of the page from Location header. I've updated the question.
-
deltheil over 10 yearsHmm... but if you try to download a file (a binary archive here) and the
Location
header redirects you to a HTML file then the archive is no more available... I assume this HTML page contains an error message, isn't it? If not, does it include information (i.e. link) related to the original file you're trying to download? In such a case you would have to parse the HTML to extract it. -
edem over 10 yearsNo, HTML page doesn't contain error info but it contain relative path to file:
<a href="_blank>/data/file/file.rar</a>
as I use with domain name to download the file but it doesn't work. I guess there is other domain name for its files but I don't know how to figure out it. -
deltheil over 10 yearsSo you need to first resolve this issue, then parse and reconstruct the right link to follow this redirection.
-
icasimpan almost 7 yearsWorks for me. Example, I'm downloading the jenkins war file which redirects, I could do
curl -O -L http://mirrors.jenkins.io/war-stable/2.60.1/jenkins.war