wget to download a link.php

44,137

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
Share:
44,137

Related videos on Youtube

caleb
Author by

caleb

Updated on September 18, 2022

Comments

  • caleb
    caleb over 1 year

    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?

  • caleb
    caleb over 12 years
    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.
  • H_7
    H_7 about 12 years
    @caleb Self-education is the best. Remember to check correct answer!
  • Mehdi LAMRANI
    Mehdi LAMRANI over 4 years
    This answer is just wrong