Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

What I am trying to do is download a file from a url like this: http://www.example.com/down/files/425/document-preview?

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 'js_username=example@example.com&js_password=123456789' --keep-session-cookies parameter -p http://www.test.co.za/test/login

wget --load-cookies cookies.txt -p www.test.co.za/downloads/doc/425399/doc-preview? --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 www.whatever.com/folder/{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 professional 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 - superuser.com/questions/301044/… –  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

2 Answers 2

use -O option will save files as the specified name

for i in {425399..525399}
do
        wget -O $i.doc --load-cookies cookies.txt -p www.test.co.za/downloads/doc/$i/doc-preview? --keep-session-cookies
done
share|improve this answer

The complete solution to the problem as stated above.

wget --save-cookies cookies.txt --post-data 'email_address=example@example.com&password=1234' --keep-session-cookies http://www.example.com/login.php

wget --load-cookies cookies.txt -p http://www.example.com/download.php?file_id=file_{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.