当前位置:网站首页>How to download files using WGet and curl

How to download files using WGet and curl

2022-07-04 18:25:00 Hua Weiyun

Usually use wget To download files . On some systems , No installation wget, Only curl You can use . Can I use a simple example to explain how I use curl Download remote files ?curl and wget Is there any difference between ?

At a high level ,wget and curl Are command line utilities that perform the same operation .

  • They can all be used FTP and HTTP(s) Download the file .
  • You can also use it curl and wget send out HTTP POST request
  • however curl Provides for programmers to use in their own code API.curl Use libcurl, It is a cross platform library .
  • wget Just one without any API Command line tools for .
  • Curl Also support more wget Protocol not supported . for example :SCP、SFTP、TFTP、TELNET、LDAP(S)、 file 、POP3、IMAP、SMTP、RTMP and RTSP.
  • Use wget There is one major advantage .wget Support recursive download , and curl I won't support it .

wget Example

The following example downloads the file and stores it under the same name as the remote server .

wget http://www.openss7.org/repos/tarballs/strx25-0.9.2.1.tar.bz2

The following example downloads the file and stores it under a different name than the remote server . When remote URL It doesn't contain url File name in , It's very useful , As shown in the following example .

wget -O taglist.zip http://www.vim.org/scripts/download_script.php?src_id=7701

Curl example

$ curl -O http://www.openss7.org/repos/tarballs/strx25-0.9.2.1.tar.bz2  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current                                 Dload  Upload   Total   Spent    Left  Speed 28 3762k   28 1085k    0     0  72771      0  0:00:52  0:00:15  0:00:37 54267

Options -O( Capitalization O) Very important . Without this ,curl Dump the downloaded file to standard output . Use -O, It will download a file with the same name as the remote server . In the example above , We are downloading strx25-0.9.2.1.tar.bz2, So the downloaded file will also have the same name .

except -O, You can also specify “--remote-name”, As shown below . Both are the same .


$ curl --remote-name http://www.openss7.org/repos/tarballs/strx25-0.9.2.1.tar.bz2

stay curl When the download , It will provide the following useful information :

  • % – The total percentage of downloads completed so far . When it reaches 100% when , Download complete . In the example above , It only downloads 28% The file of .
  • Total – Total file size
  • Received - Total size of files downloaded so far . In the example above , It has been downloaded so far 1085k( in total 3762k)
  • Xferd – This will be used when you upload some files to the remote server . During upload , This will indicate the total size of the files uploaded so far . Because we are downloading a file , In this case , This is a 0.
  • Average Speed Dload – This represents the average download speed .
  • AVerage Speed Upload  – When uploading files , This will indicate the average upload speed
  • Time Total – This means that according to the current download ( Or upload ) Speed download ( Or upload ) The total time required for the entire document . In this example , It takes about... To download this file in total 52 second .
  • Time Spend – curl Download so far ( Or upload ) The time it takes to file . In this case , So far it has cost 15 second .
  • Time Left – That's according to a “ Total time ”——“ Time spent ” Calculated .
  • Current Speed – - This indicates the current download / Upload speed . Compare this with average acceleration Dload/UPload Compare , To see how fast or slow your system is currently downloading .

If you want to download a file and store it in a name different from the file name in the remote server , Please use -o( A lowercase letter o), As shown below . When remote URL It doesn't contain url File name in , It's very useful , As shown in the following example .

$  curl -o taglist.zip http://www.vim.org/scripts/download_script.php?src_id=7701  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current                                 Dload  Upload   Total   Spent    Left  Speed100 50243  100 50243    0     0   170k      0 --:--:-- --:--:-- --:--:--  400k

In the example above , long-range URL No file name in , It just calls a php Script , Pass some parameters to it . however , The file will be downloaded and saved as taglist.zip. Instead of -o, You can also specify “–output”.

原网站

版权声明
本文为[Hua Weiyun]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/185/202207041632165408.html