wget to download a link.php
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
Related videos on Youtube
caleb
Updated on September 18, 2022Comments
-
caleb over 1 year
I am having trouble finding a way to use
wget
to download a file from a link that usesphp
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 :
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 over 12 yearsMurphy'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 about 12 years@caleb Self-education is the best. Remember to check correct answer!
-
Mehdi LAMRANI over 4 yearsThis answer is just wrong