How to rename a downloaded file using wget?

To download SOFA statistics from the server, I use the wget command:

wget -c http://sourceforge.net/projects/sofastatistics/files/latest/download?source=dlp 

In this case, the file name of the downloaded file is download?source=files . If I add the --output-document option to the command to rename the output file to sofastatistics-latest.deb , the format of the downloaded file will not be recognized by the dpkg package.

 dpkg-deb: error: `sofastatistics-latest.deb' is not a debian format archive 

How to rename a downloaded file using wget?

UPDATE - January 08 '15

With the provided link, the downloaded file will always be * .tar.gz. To get it with a real name, just add the --content-disposition option like this (thanks @ 6EQUJ5!):

 wget --content-disposition http://sourceforge.net/projects/sofastatistics/files/latest/download?source=dlp 

But I need a * .deb file, so @creaktive was right here, I had to look for a link in a * .deb file.

Thanks everyone for the answers!

+45
wget file-rename
Jan 13 '13 at 17:54
source share
3 answers

Redirecting standard output to an arbitrary file name always works. You do it right, as the wget person says, using -O

 wget http://www.kernel.org/pub/linux/kernel/README -O foo --2013-01-13 18:59:44-- http://www.kernel.org/pub/linux/kernel/README Resolving www.kernel.org... 149.20.4.69, 149.20.20.133 Connecting to www.kernel.org|149.20.4.69|:80... connected. HTTP request sent, awaiting response... 200 OK Length: 12056 (12K) [text/plain] Saving to: `foo' 100%[======================================================================================================================================>] 12,056 --.-K/s in 0.003s 2013-01-13 18:59:45 (4.39 MB/s) - `foo' saved [12056/12056] 

In fact, you should get the HTML in your file (you can usually check it using the man file).

[EDIT]

In your case, the client gets 302 Found (you can check it using curl -v URL ).

The following twisting does a 3xx trick:

 $ curl -L http://sourceforge.net/projects/sofastatistics/files/latest/download?source=files -o foo.deb % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 0 463 0 0 0 0 0 0 --:--:-- 0:00:01 --:--:-- 0 0 0 0 0 0 0 0 0 --:--:-- 0:00:02 --:--:-- 0 100 2035k 100 2035k 0 0 390k 0 0:00:05 0:00:05 --:--:-- 1541k $ file foo.deb foo.deb: gzip compressed data, was "sofastats-1.3.1.tar", last modified: Thu Jan 10 00:30:44 2013, max compression 

There should be a similar option for wget to carry HTTP redirects.

+52
Jan 13 '13 at 18:01
source share

If you have to do the same download from a web browser, and notice that the browser did indeed correctly name the file, you can use the --content-disposition option to give wget the same behavior:

 wget --content-disposition http://sourceforge.net/projects/sofastatistics/files/latest/download?source=dlp 

My Debian man page reports this as an โ€œexperimentalโ€ function, but I cannot remember that it does not work for me:

  --content-disposition If this is set to on, experimental (not fully-functional) support for "Content-Disposition" headers is enabled. This can currently result in extra round-trips to the server for a "HEAD" request, and is known to suffer from a few bugs, which is why it is not currently enabled by default. This option is useful for some file-downloading CGI programs that use "Content-Disposition" headers to describe what the name of a downloaded file should be. 
+12
Jan 07 '15 at 9:36
source share

This link points to the redirector, not the final destination! This way you load the HTML and rename it to .deb . A cluttered page has this at the top:

Your download will start in 0 seconds ... Problems with the download? Use the direct link or try another mirror .

Now this is a valid link (note the download prefix): http://downloads.sourceforge.net/project/sofastatistics/sofastatistics/1.3.1/sofastats-1.3.1-1_all.deb?r=http%3A%2F% 2Fsourceforge.net% 2Fprojects% 2Fsofastatistics% 2Ffiles% 2Fsofastatistics% 2F1.3.1% 2F & ts = 1358119361 & use_mirror = ufpr

Pass this wget url. Also note that SourceForge is trying to outwit you by inviting the operating system through the User-Agent string. The best guess for "wget" is like the .tar.gz package. So you should be more specific when requesting a deb file!

+1
Jan 13 '13 at 18:01
source share



All Articles