≡ Menu

wget vs curl: How to Download Files Using wget and curl

Question: I typically use wget to download files. On some systems, wget is not installed and only curl is available. Can you explain me with a simple example on how I can download a remote file using curl? Are there any difference between curl and wget?

Answer: On a high-level, both wget and curl are command line utilities that do the same thing.

  • They both can be used to download files using FTP and HTTP(s).
  • You can also send HTTP POST request using curl and wget
  • However curl provides APIs that can be used by programmers inside their own code. curl uses libcurl which is a cross-platform library.
  • wget is just a command-line tool without any APIs.
  • Curl also supports lot more protocols that wget doesn’t support. For example: SCP, SFTP, TFTP, TELNET, LDAP(S), FILE, POP3, IMAP, SMTP, RTMP and RTSP.
  • There is a major advantage of using wget. wget supports recursive download, while curl doesn’t.

Wget Examples

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

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

The following example download the file and stores in a different name than the remote server. This is helpful when the remote URL doesn’t contain the file name in the url as shown in the example below.

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

More wget examples: The Ultimate Wget Download Guide With 15 Awesome Examples

Curl Examples

$ 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

Option -O (upper-case O) is important. Without this, curl will start dumping the downloaded file on the stdout. Using -O, it downloads the files in the same name as the remote server. In the above example, we are downloading strx25-0.9.2.1.tar.bz2, so the downloaded file will also be the same name.

Instead of -O, you an 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

While curl is downloading it gives the following useful information:

  • % – The total % of the download that was completed as of now. When it gets to 100% the download is completed. In the above example, it has downloaded only 28% of the file.
  • Total – The total size of the file
  • Received – The total size of the file that was has been downloaded so far. In the above example, it has downloaded 1085k so far (out of 3762k total)
  • Xferd – This will be used when you upload some files to the remote server. During upload, this will indicate the total size of the file that has been uploaded so far. Since we are downloading a file, in this example, this is 0.
  • Average Speed Dload – This indicates the average download speed.
  • AVerage Speed Upload – While uploading a file, this will indicate the average upload speed
  • Time Total – This indicates the total time it will take to download (or upload) the whole file based on the current download (or upload) speed. In this example, it will take approximately a total of 52 seconds to download this file.
  • Time Spend – The time curl has spent so far downloading (or uploading) the file. In this example, it has spent 15 seconds so far.
  • Time Left – This is caculated based on “Time Total” – “Time Spent”.
  • Current Speed – This indicates the current download/upload speed. Compare this with Average Spped Dload/UPload to see how fast or slow your system is downloading currently.

If you want to download the file and store it in a different name than the name of the file in the remote server, use -o (lower-case o) as shown below. This is helpful when the remote URL doesn’t contain the file name in the url as shown in the example below.

$  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  Speed
100 50243  100 50243    0     0   170k      0 --:--:-- --:--:-- --:--:--  400k

In the above example, there is no file name in the remote URL, it just calls a php script that passes some parameter to it. However, the file will be downloaded and saved as taglist.zip on your local system. Instead of -o, you an also specify, “–output”.

More curl examples: 15 Practical Linux cURL Command Examples

Add your comment

If you enjoyed this article, you might also like..

  1. 50 Linux Sysadmin Tutorials
  2. 50 Most Frequently Used Linux Commands (With Examples)
  3. Top 25 Best Linux Performance Monitoring and Debugging Tools
  4. Mommy, I found it! – 15 Practical Linux Find Command Examples
  5. Linux 101 Hacks 2nd Edition eBook Linux 101 Hacks Book

Bash 101 Hacks Book Sed and Awk 101 Hacks Book Nagios Core 3 Book Vim 101 Hacks Book

Comments on this entry are closed.

  • Jalal Hajigholamali July 6, 2012, 8:48 am

    Hi,

    thanks, Very nice article

  • manoj July 6, 2012, 9:19 am

    Thanks so muc for the info…….helpful to many guys

  • al July 9, 2012, 12:59 am

    You sure know how to make useful posts!

  • Jatin July 31, 2012, 10:48 am

    Is there any way to download specific type of file form a site using wget or curl?
    Suppose, I want to download just the .jpg files from my site.

  • praveen August 1, 2012, 5:46 am

    Thank you..good info..

  • G Gayatri Soumya February 13, 2013, 10:35 pm

    Hi,

    I am trying to download a file from GE library. However, we need to login to GE network before downloading. So ,is there any option to give login credentials like my user id and password in the code so that i can download the file.
    Please share your comments,

    Your help is appreciated.

    Thanks
    Gayatri

  • Jon May 14, 2013, 6:25 am

    How can I use this to download the latest version of to date of say a text.txt file from my web site?

  • Sasha April 16, 2014, 9:34 am

    Thx a lot!

  • Mirak April 27, 2014, 12:31 pm

    I want downloading file for video

  • Ashish makwana October 16, 2014, 6:41 am

    Its awesome. i love your code. thank you so much… your website is become an angel form because i am tired to find out wget optimum use of code.thanks again.

  • Mahesh November 2, 2014, 10:00 pm

    Thanks you for all the useful posts and do continue the good work.

  • Mahesh November 2, 2014, 10:01 pm

    Thank you for all the useful posts and do continue the good work.

  • laelia June 14, 2015, 12:39 am

    Thank you. Please help me answer that how to resume download file when file was interrupted?
    Wish you a good day.

  • Important Dude September 14, 2015, 1:56 am

    It’s probably a smart move to also use the -L option with curl, which will follow any HTTP redirects.

  • haans May 18, 2016, 7:33 pm

    What if a site requires authentication prior able to download? Eg: mysql binary?

    http://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.12-linux-glibc2.5-x86_64.tar

  • Shubham Gupta January 4, 2017, 5:29 am

    Hi.

    Thanks for the article.

    2 quick questions-
    (1). When I followed using curl -O example why the file being downloaded has a name of file as “pdf?cycleId=1” where it is picking up the last 2 words from my request ?

    (2). I would like to know how can I pass Method type (GET or POST) with curl -O ?

  • phil May 1, 2017, 10:45 pm

    using curl, how do i continue the download from where it ended after it timedout