Impossible to wget a link with php redirection

I tried all the tricks I could find to download this link from terminal using wget and curl :
None succeeded to get me the epub book that I can simply download by clicking 'get' button when opening the link in a browser. I rather download it using consol, is it even possible to do so ?

2

3 Answers

The answer is to open the link you've been given. You'll probably notice something that says "GET" at the top of your web page

Use wget on that link.

wget ""

It will put that in your current directory. The last thing you have to do is rename the file.

mv 'get.php?md5=5c757ea95b47ceab5065b26eeb55896a&key=FIS7AXJH8YP1OC66' random.epub

Then you can open your epub file in an ebook reader.

1

You might have better luck using curl to do this instead of wget, and set it to follow the redirection using the switches -L, -J, and -O.

curl -O -J -L 

A bit of info on these switches from the documentation:

-O/--remote-name Write output to a local file named like the remote file we get. (Only the file part of the remote file is used, the path is cut off.)
-L/--location (HTTP/HTTPS) If the server reports that the requested page has moved to a different location (indicated with a Location: header and a 3XX response code), this option will make curl redo the request on the new place. If used together with -i/--include or -I/--head, headers from all requested pages will be shown. When authentication is used, curl only sends its credentials to the initial host. If a redirect takes curl to a different host, it won't be able to intercept the user+password. See also --location-trusted on how to change this. You can limit the amount of redirects to follow by using the --max-redirs option.
-J/--remote-header-name (HTTP) This option tells the -O/--remote-name option to use the server-specified Content-Disposition filename instead of extracting a filename from the URL.
1

@mondotofu got close to the right answer.

Your problem isn't PHP redirection. You need recursion. The link you provided yields a static HTML page with another link to the actual content. In order to get to the content you need to follow the link manually. Or use Wget's recursion options to do it automatically.

The main thing mondotofu missed was using --content-disposition in order to ask Wget to use the name provided by the server which gets you the right filename instead of needing to use mv

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like