Ubuntu – How to use wget to download a file which can be downloaded by firefox’ default downloader

wget

I try to use wget to download this but failed.

https://code.ros.org/trac/wg-ros-pkg/raw-attachment/ticket/5069/rein_cmakelists2.patch

  sam@sam:/media/Data/code/ros/recognition/rein$ wget https://code.ros.org/trac/wg-ros-pkg/raw-attachment/ticket/5069/rein_cmakelists2.patch
  --2012-10-04 16:29:30--  https://code.ros.org/trac/wg-ros-pkg/raw-attachment/ticket/5069/rein_cmakelists2.patch
  Resolving code.ros.org (code.ros.org)... 157.22.19.21
  Connecting to code.ros.org (code.ros.org)|157.22.19.21|:443... connected.
  HTTP request sent, awaiting response... Read error (Connection reset by peer) in headers.
  Retrying.

  --2012-10-04 16:29:32--  (try: 2)  https://code.ros.org/trac/wg-ros-pkg/raw-attachment/ticket/5069/rein_cmakelists2.patch
  sam@sam:/media/Data/code/ros/recognition/rein$                                                                        

But I can use firefox to download.

How to download this kind of file in wget?

Thank you~

Best Answer

Some websites or servers block wget (and similar tools) in order to only allow downloads from a browser. You can trick the website into thinking that you are an actual browser. There are many examples available on google. Here is a particularly complete one taken from askapache. To find alternatives just google wget pretend browser.

wget 
  --referer="http://www.google.com" 
  --user-agent="Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6" 
  --header="Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5" 
  --header="Accept-Language: en-us,en;q=0.5" 
  --header="Accept-Encoding: gzip,deflate"
  --header="Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7" 
  --header="Keep-Alive: 300" 
  -dnv [THE URL; in your case: https://code.ros.org/trac/wg-ros-pkg/raw-attachment]/ticket/5069/rein_cmakelists2.patch

This is one command, though I put it on several lines to increase readability. You can make it an alias to make it easier to use.

Related Question