TranslateProject/sources/tech/20180102 cURL vs. wget- Their Differences, Usage and Which One You Should Use.md

3.9 KiB

cURL vs. wget: Their Differences, Usage and Which One You Should Use

For downloading files directly from the Linux command line, there are two utilities that immediately come to mind: wget and cURL. They share a lot of features and can easily get many of the same tasks accomplished.

Though they share similar features, they aren't exactly the same. These programs fit slightly different roles and use cases, and do have traits that make each better for certain situations.

cURL vs wget: Their Similarities

Both wget and cURL can download things. At their core, that's what they both do. They can make requests of the Internet and pull back the requested item. That could be a file, picture, or even the raw HTML of a website.

Both programs are also capable of making HTTP POST requests. This means they can send data to a website, like filling out a form.

Since both are command line tools, they were also both designed to be scriptable. You can include both wget and cURL in your Bash scripts to automatically interact with online content and retrieve what you need.

wget Advantages

wget download

wget is simple and straightforward. It's meant for quick downloads, and it's excellent at it. wget is a single self-contained program. It doesn't require any extra libraries, and it's not meant to do anything beyond the scope of what it does.

Because wget is so tailored for straight downloads, it also has the ability to download recursively. That allows you to download everything on a page or all of the files in an FTP directory at once.

wget also has intelligent defaults. It specifies how to handle a lot of things that a normal browser would, like cookies and redirects, without the need to add any configuration. Lastly, wget works out of the box.

cURL Advantages

cURL Download

cURL is a multi-tool. Sure, it can download content from the Internet. It can do a lot more, too.

cURL is powered by a library: libcurl. This means you can write entire programs based on cURL, allowing you to base graphical download pograms on libcurl and get access to all of its functionality.

The wide range or protocols that cURL supports are probably the biggest selling point it has. cURL can access websites over HTTP and HTTPS and can handle FTP in both directions. It supports LDAP and even Samba shares. You can actually use cURL to send and retrieve email.

cURL has some neat security features, too. cURL supports loads of SSL/TLS libraries. It also supports Internet access via proxies, including SOCKS. That means you can use cURL over Tor.

cURL also supports gzip compression to send large amounts of data more easily.

Closing Thoughts

So should you use cURL or wget? That really depends. If you want to download something quickly without needing to worry about flags, then you should go with wget. It's simple and just works. If you want to do something more complex, cURL should be your immediate choice.

cURL allows you to do a lot more. You can think of cURL like a stripped-down command line web browser. It supports just about every protocol you can think of and can access and interact with nearly all online content. The only is that a browser renders the responses that it receives, and cURL doesn't.


via: https://www.maketecheasier.com/curl-vs-wget/

作者:Nick Congleton 译者:译者ID 校对:校对者ID

本文由 LCTT 原创编译,Linux中国 荣誉推出