4

I am having trouble finding a way to use wget to download a file from a link that uses php to point to the download.

For example, if I want to write a script to download... say superantispyware portable every day so I have a fresh copy all the time (only handy if you run windows, which I don't but I digress) the download link looks like :

http://www.superantispyware.com/sasportable.php

I don't want the PHP file, I want the file it links to. In a browser I assume some server side magic happens to make this work. Is there an incantation I can use to emulate what my browser does? can curl do this?

2 Answers 2

7

By default, the filename of the URL is used as the target filename. If redirection occurs, it is preferable to use the final filename. That can be accomplished with the --trust-server-names option of wget:

wget --trust-server-names http://example.com/file.php

From the manual page of wget:

--trust-server-names
If this is set to on, on a redirect the last component of the redirection URL will be used as the local file name. By default it is used the last component in the original URL.

If the target filename is not what you intended, you can use the -O (long option: --output-document) option as in:

wget http://example.com/file.php -O meh.tar.gz
0

The "magic" is server side, not in the browser, so you just wget or curl the url.

3
  • Murphy's Law would say I'd find the answer just after I post a question (very educational 4 hours though, I now know wget and curl better than I would without a problem like this!) This can be done with the -O (wget) or -o (curl). Following the example above- curl -o sas.com superantispyware.com/sasportable.php OR wget -O sas.com superantispyware.com/sasportable.php The output file seems to need to be renamed to match the extension of what I want to download, or else it ends in .php and won't execute.
    – caleb
    Jan 30, 2012 at 19:22
  • 1
    @caleb Self-education is the best. Remember to check correct answer!
    – H_7
    Feb 13, 2012 at 5:36
  • This answer is just wrong Nov 24, 2019 at 14:49

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.