Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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? is it impossible? I want to do this so I can update a series of programs, and as the list grows, it's becoming a real chore!

share|improve this question

2 Answers 2

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|improve this answer

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

share|improve this answer
    
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 '12 at 19:22
1  
@caleb Self-education is the best. Remember to check correct answer! –  H_7 Feb 13 '12 at 5:36

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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