Difference between revisions of "Curl"

From Christoph's Personal Wiki
Jump to: navigation, search
m (Curl (command) moved to Curl)
Line 49: Line 49:
 
<pre>curl -O www.haxx.se/index.html -O curl.haxx.se/download.html</pre>
 
<pre>curl -O www.haxx.se/index.html -O curl.haxx.se/download.html</pre>
  
== See also ==
+
==Using Curl for fast downloads==
 +
Suppose you want to download the Mandrake 8.0 ISO from the following three locations:
 +
url1=http://ftp.eecs.umich.edu/pub/linux/mandrake/iso/Mandrake80-inst.iso
 +
url2=http://ftp.rpmfind.net/linux/Mandrake/iso/Mandrake80-inst.iso
 +
url3=http://ftp.wayne.edu/linux/mandrake/iso/Mandrake80-inst.iso
 +
 
 +
The length of the file is 677281792, so initiate three simultaneous downloads using curl's "--range" option:
 +
bash$ curl -r 0-199999999 -o mdk-iso.part1 $url1 &
 +
bash$ curl -r 200000000-399999999 -o mdk-iso.part2 $url2 &
 +
bash$ curl -r 400000000- -o mdk-iso.part3 $url3 &
 +
 
 +
==See also==
 
*[[Curl/manual|cURL manual]] &mdash; by the Haxx Team
 
*[[Curl/manual|cURL manual]] &mdash; by the Haxx Team
 
*[[wget]]
 
*[[wget]]

Revision as of 01:48, 5 August 2007

cURL is a command line tool for transferring files with URL syntax, supporting FTP, FTPS, HTTP, HTTPS, TFTP, Telnet, DICT, FILE and LDAP. cURL supports HTTPS certificates, HTTP POST, HTTP PUT, FTP uploading, Kerberos, HTTP form based upload, proxies, cookies, user+password authentication (Basic, Digest, NTLM and Negotiate for HTTP and kerberos4 for FTP), file transfer resume, http proxy tunneling and many other features. cURL is open source/free software distributed under MIT License.

The main purpose and use for cURL is to automate unattended file transfers or sequences of operations. It is for example a good tool for simulating a user's actions at a web browser.

Libcurl is the corresponding library/API that users may incorporate into their programs; cURL acts as a stand-alone wrapper to the libcurl library. libcurl is being used to provide URL transfer capabilities to numerous applications, Open Source as well as many commercial ones.

Simple usage

  • Get the main page from firefox's web-server:
curl http://www.firefox.com/
  • Get the README file the user's home directory at funet's ftp-server:
curl ftp://ftp.funet.fi/README
  • Get a web page from a server using port 8000:
curl http://www.weirdserver.com:8000/
  • Get a list of a directory of an FTP site:
curl ftp://cool.haxx.se/
  • Get a gopher document from funet's gopher server:
curl gopher://gopher.funet.fi
  • Get the definition of curl from a dictionary:
curl dict://dict.org/m:curl
  • Fetch two documents at once:
curl ftp://cool.haxx.se/ http://www.weirdserver.com:8000/

Download to a file

  • Get a web page and store in a local file:
curl -o thatpage.html http://www.netscape.com/
  • Get a web page and store in a local file, make the local file get the name of the remote document (if no file name part is specified in the URL, this will fail):
curl -O http://www.netscape.com/index.html
  • Fetch two files and store them with their remote names:
curl -O www.haxx.se/index.html -O curl.haxx.se/download.html

Using Curl for fast downloads

Suppose you want to download the Mandrake 8.0 ISO from the following three locations:

url1=http://ftp.eecs.umich.edu/pub/linux/mandrake/iso/Mandrake80-inst.iso
url2=http://ftp.rpmfind.net/linux/Mandrake/iso/Mandrake80-inst.iso
url3=http://ftp.wayne.edu/linux/mandrake/iso/Mandrake80-inst.iso
The length of the file is 677281792, so initiate three simultaneous downloads using curl's "--range" option:
bash$ curl -r 0-199999999 -o mdk-iso.part1 $url1 &
bash$ curl -r 200000000-399999999 -o mdk-iso.part2 $url2 &
bash$ curl -r 400000000- -o mdk-iso.part3 $url3 &

See also

External links