Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

What I am trying to do is download a file from a url like this:

When I visit this url in my browser, it triggers a file called for example: 425.doc this can be a pdf, rtf, txt, docx etc. file format.

wget is currently saving this file as: document-preview? is there anyway to save it as the file download that is triggered by the url?

This is what I am doing so far:

wget --save-cookies cookies.txt --post-data '' --keep-session-cookies parameter -p

wget --load-cookies cookies.txt -p --keep-session-cookies

I want to change the values in a loop of the 425399 for example: from 425399 to 525399 it logs in perfectly and downloads, just want to capture filename and save it as that filename instead of doc-preview? which does not save the right file name which should be: 425399.doc

I did get this example online to do the batch download: wget{1..30}.html

but my problem is the file name

share|improve this question

closed as off topic by EightBitTony, Scott Pack, freiheit, Michael Hampton, Ward Dec 17 '12 at 0:01

Questions on Server Fault are expected to relate to server, networking, or related infrastructure administration within the scope defined by the community. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about reopening questions here.If this question can be reworded to fit the rules in the help center, please edit the question.

Probably off-topic for SF, on-topic at SuperUser, but already asked and answered here -… – EightBitTony Jun 11 '12 at 23:06
Thanks for your help, that was the correct answer. Sorry for posing in the wrong place. – louis_coetzee Jun 11 '12 at 23:13

use -O option will save files as the specified name

for i in {425399..525399}
        wget -O $i.doc --load-cookies cookies.txt -p$i/doc-preview? --keep-session-cookies
share|improve this answer

The complete solution to the problem as stated above.

wget --save-cookies cookies.txt --post-data '' --keep-session-cookies

wget --load-cookies cookies.txt -p{1..5000} --content-disposition --directory-prefix=downloads
share|improve this answer

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