How to rename the downloaded file with wget?
Asked Answered
I

4

105

To download the SOFA Statistics from the server I use the wget command:

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

The filename of downloaded file in this case 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 downloaded file is not recognized by dpkg package.

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

How to rename correctly the downloaded file with wget?

UPDATE - Jan 08 '15

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

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

But I needed a *.deb file, so here was right the @creaktive, I had to search for a *.deb file link.

Thanks to all for the answers!

Inward answered 13/1, 2013 at 17:54 Comment(7)
If dpkg says that, it really is not a Debian archive... What does file say?Closeup
The URL you mentioned is a HTML page.Jelks
I think you accepted the wrong answer.Metalwork
@Metalwork It isn't wrong, it is partial, but you are right, I must not accept this answer as the correct one.Inward
I've found --trust-server-names is more appropriate for my uses. See also this duplicate SO question and the same question on Unix.SE.Sharonsharona
Possible duplicate of wget command to download a file and save as a different filenameThermometry
@PeterMortensen Probably, you want to say that the question you mentioned is a possible duplicate of my question? See the publication date.Inward
C
135

A redirect of standard output into arbitrary file name always works. You are doing it correctly as man wget 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]

Indeed, you must be getting an HTML in your file (usually can be checked with man file).

[EDIT]

In your case client is receiving 302 Found (you can check it with curl -v URL).

The following curl does the trick by respecting the 3xx:

$ 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 similar option for wget to tolerate HTTP redirects.

Cachalot answered 13/1, 2013 at 18:1 Comment(0)
S
24

If you were to do the same download from a web browser, and you notice the browser actually naming the file correctly, you can use the --content-disposition option to give wget the same behaviour:

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

My Debian man page reports this as an 'experimental' feature but I cant recall it not working 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.
Sodomy answered 7/1, 2015 at 9:36 Comment(0)
D
1

That link points to a redirector, not the final destination! So you're downloading HTML and renaming it to .deb. The cluttered page has this around the top:

Your download will start in 0 seconds... Problems with the download? Please use this 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 URL to wget. Also, note that SourceForge tries to outsmart you, guesting the operational system via the User-Agent string. The best guess for "wget" seems to be the .tar.gz package. So, you should be more specific, requesting the deb file!

Divulgence answered 13/1, 2013 at 18:1 Comment(1)
There is a .tar.gz version for this software: sourceforge.net/projects/sofastatistics/files/sofastatistics/… Make sure you select the .deb link!Divulgence
B
1

This worked out for me

  • on macOS I installed wget via Homebrew so with this brew install wget
  • then I execute this wget -O ~/Downloads/file.txt https://www.gnu.org
  • or this is the same wget --output-document ~/Downloads/fil.txt https://www.gnu.org
Benton answered 11/11, 2021 at 16:50 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.