How to rename the downloaded file with wget?

前端 未结 3 1143
南笙
南笙 2021-01-30 09:58

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
<         


        
3条回答
  •  遥遥无期
    2021-01-30 10:46

    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.

提交回复
热议问题