MANUAL 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991
  1. LATEST VERSION
  2. You always find news about what's going on as well as the latest versions
  3. from the curl web pages, located at:
  4. http://curl.haxx.se
  5. SIMPLE USAGE
  6. Get the main page from Netscape's web-server:
  7. curl http://www.netscape.com/
  8. Get the README file the user's home directory at funet's ftp-server:
  9. curl ftp://ftp.funet.fi/README
  10. Get a web page from a server using port 8000:
  11. curl http://www.weirdserver.com:8000/
  12. Get a list of a directory of an FTP site:
  13. curl ftp://cool.haxx.se/
  14. Get the definition of curl from a dictionary:
  15. curl dict://dict.org/m:curl
  16. Fetch two documents at once:
  17. curl ftp://cool.haxx.se/ http://www.weirdserver.com:8000/
  18. Get a file off an FTPS server:
  19. curl ftps://files.are.secure.com/secrets.txt
  20. or use the more appropriate FTPS way to get the same file:
  21. curl --ftp-ssl ftp://files.are.secure.com/secrets.txt
  22. Get a file from an SSH server using SFTP:
  23. curl -u username sftp://shell.example.com/etc/issue
  24. Get a file from an SSH server using SCP using a private key to authenticate:
  25. curl -u username: --key ~/.ssh/id_dsa --pubkey ~/.ssh/id_dsa.pub \
  26. scp://shell.example.com/~/personal.txt
  27. Get the main page from an IPv6 web server:
  28. curl -g "http://[2001:1890:1112:1::20]/"
  29. DOWNLOAD TO A FILE
  30. Get a web page and store in a local file:
  31. curl -o thatpage.html http://www.netscape.com/
  32. Get a web page and store in a local file, make the local file get the name
  33. of the remote document (if no file name part is specified in the URL, this
  34. will fail):
  35. curl -O http://www.netscape.com/index.html
  36. Fetch two files and store them with their remote names:
  37. curl -O www.haxx.se/index.html -O curl.haxx.se/download.html
  38. USING PASSWORDS
  39. FTP
  40. To ftp files using name+passwd, include them in the URL like:
  41. curl ftp://name:passwd@machine.domain:port/full/path/to/file
  42. or specify them with the -u flag like
  43. curl -u name:passwd ftp://machine.domain:port/full/path/to/file
  44. FTPS
  45. It is just like for FTP, but you may also want to specify and use
  46. SSL-specific options for certificates etc.
  47. Note that using FTPS:// as prefix is the "implicit" way as described in the
  48. standards while the recommended "explicit" way is done by using FTP:// and
  49. the --ftp-ssl option.
  50. SFTP / SCP
  51. This is similar to FTP, but you can specify a private key to use instead of
  52. a password. Note that the private key may itself be protected by a password
  53. that is unrelated to the login password of the remote system. If you
  54. provide a private key file you must also provide a public key file.
  55. HTTP
  56. Curl also supports user and password in HTTP URLs, thus you can pick a file
  57. like:
  58. curl http://name:passwd@machine.domain/full/path/to/file
  59. or specify user and password separately like in
  60. curl -u name:passwd http://machine.domain/full/path/to/file
  61. HTTP offers many different methods of authentication and curl supports
  62. several: Basic, Digest, NTLM and Negotiate. Without telling which method to
  63. use, curl defaults to Basic. You can also ask curl to pick the most secure
  64. ones out of the ones that the server accepts for the given URL, by using
  65. --anyauth.
  66. NOTE! Since HTTP URLs don't support user and password, you can't use that
  67. style when using Curl via a proxy. You _must_ use the -u style fetch
  68. during such circumstances.
  69. HTTPS
  70. Probably most commonly used with private certificates, as explained below.
  71. PROXY
  72. curl supports both HTTP and SOCKS proxy servers, with optional authentication.
  73. It does not have special support for FTP proxy servers since there are no
  74. standards for those, but it can still be made to work with many of them. You
  75. can also use both HTTP and SOCKS proxies to transfer files to and from FTP
  76. servers.
  77. Get an ftp file using an HTTP proxy named my-proxy that uses port 888:
  78. curl -x my-proxy:888 ftp://ftp.leachsite.com/README
  79. Get a file from a HTTP server that requires user and password, using the
  80. same proxy as above:
  81. curl -u user:passwd -x my-proxy:888 http://www.get.this/
  82. Some proxies require special authentication. Specify by using -U as above:
  83. curl -U user:passwd -x my-proxy:888 http://www.get.this/
  84. A comma-separated list of hosts and domains which do not use the proxy can
  85. be specified as:
  86. curl --noproxy localhost,get.this -x my-proxy:888 http://www.get.this/
  87. If the proxy is specified with --proxy1.0 instead of --proxy or -x, then
  88. curl will use HTTP/1.0 instead of HTTP/1.1 for any CONNECT attempts.
  89. curl also supports SOCKS4 and SOCKS5 proxies with --socks4 and --socks5.
  90. See also the environment variables Curl supports that offer further proxy
  91. control.
  92. Most FTP proxy servers are set up to appear as a normal FTP server from the
  93. client's perspective, with special commands to select the remote FTP server.
  94. curl supports the -u, -Q and --ftp-account options that can be used to
  95. set up transfers through many FTP proxies. For example, a file can be
  96. uploaded to a remote FTP server using a Blue Coat FTP proxy with the
  97. options:
  98. curl -u "Remote-FTP-Username@remote.ftp.server Proxy-Username:Remote-Pass" \
  99. --ftp-account Proxy-Password --upload-file local-file \
  100. ftp://my-ftp.proxy.server:21/remote/upload/path/
  101. See the manual for your FTP proxy to determine the form it expects to set up
  102. transfers, and curl's -v option to see exactly what curl is sending.
  103. RANGES
  104. With HTTP 1.1 byte-ranges were introduced. Using this, a client can request
  105. to get only one or more subparts of a specified document. Curl supports
  106. this with the -r flag.
  107. Get the first 100 bytes of a document:
  108. curl -r 0-99 http://www.get.this/
  109. Get the last 500 bytes of a document:
  110. curl -r -500 http://www.get.this/
  111. Curl also supports simple ranges for FTP files as well. Then you can only
  112. specify start and stop position.
  113. Get the first 100 bytes of a document using FTP:
  114. curl -r 0-99 ftp://www.get.this/README
  115. UPLOADING
  116. FTP / FTPS / SFTP / SCP
  117. Upload all data on stdin to a specified server:
  118. curl -T - ftp://ftp.upload.com/myfile
  119. Upload data from a specified file, login with user and password:
  120. curl -T uploadfile -u user:passwd ftp://ftp.upload.com/myfile
  121. Upload a local file to the remote site, and use the local file name remote
  122. too:
  123. curl -T uploadfile -u user:passwd ftp://ftp.upload.com/
  124. Upload a local file to get appended to the remote file:
  125. curl -T localfile -a ftp://ftp.upload.com/remotefile
  126. Curl also supports ftp upload through a proxy, but only if the proxy is
  127. configured to allow that kind of tunneling. If it does, you can run curl in
  128. a fashion similar to:
  129. curl --proxytunnel -x proxy:port -T localfile ftp.upload.com
  130. HTTP
  131. Upload all data on stdin to a specified http site:
  132. curl -T - http://www.upload.com/myfile
  133. Note that the http server must have been configured to accept PUT before
  134. this can be done successfully.
  135. For other ways to do http data upload, see the POST section below.
  136. VERBOSE / DEBUG
  137. If curl fails where it isn't supposed to, if the servers don't let you in,
  138. if you can't understand the responses: use the -v flag to get verbose
  139. fetching. Curl will output lots of info and what it sends and receives in
  140. order to let the user see all client-server interaction (but it won't show
  141. you the actual data).
  142. curl -v ftp://ftp.upload.com/
  143. To get even more details and information on what curl does, try using the
  144. --trace or --trace-ascii options with a given file name to log to, like
  145. this:
  146. curl --trace trace.txt www.haxx.se
  147. DETAILED INFORMATION
  148. Different protocols provide different ways of getting detailed information
  149. about specific files/documents. To get curl to show detailed information
  150. about a single file, you should use -I/--head option. It displays all
  151. available info on a single file for HTTP and FTP. The HTTP information is a
  152. lot more extensive.
  153. For HTTP, you can get the header information (the same as -I would show)
  154. shown before the data by using -i/--include. Curl understands the
  155. -D/--dump-header option when getting files from both FTP and HTTP, and it
  156. will then store the headers in the specified file.
  157. Store the HTTP headers in a separate file (headers.txt in the example):
  158. curl --dump-header headers.txt curl.haxx.se
  159. Note that headers stored in a separate file can be very useful at a later
  160. time if you want curl to use cookies sent by the server. More about that in
  161. the cookies section.
  162. POST (HTTP)
  163. It's easy to post data using curl. This is done using the -d <data>
  164. option. The post data must be urlencoded.
  165. Post a simple "name" and "phone" guestbook.
  166. curl -d "name=Rafael%20Sagula&phone=3320780" \
  167. http://www.where.com/guest.cgi
  168. How to post a form with curl, lesson #1:
  169. Dig out all the <input> tags in the form that you want to fill in. (There's
  170. a perl program called formfind.pl on the curl site that helps with this).
  171. If there's a "normal" post, you use -d to post. -d takes a full "post
  172. string", which is in the format
  173. <variable1>=<data1>&<variable2>=<data2>&...
  174. The 'variable' names are the names set with "name=" in the <input> tags, and
  175. the data is the contents you want to fill in for the inputs. The data *must*
  176. be properly URL encoded. That means you replace space with + and that you
  177. write weird letters with %XX where XX is the hexadecimal representation of
  178. the letter's ASCII code.
  179. Example:
  180. (page located at http://www.formpost.com/getthis/
  181. <form action="post.cgi" method="post">
  182. <input name=user size=10>
  183. <input name=pass type=password size=10>
  184. <input name=id type=hidden value="blablabla">
  185. <input name=ding value="submit">
  186. </form>
  187. We want to enter user 'foobar' with password '12345'.
  188. To post to this, you enter a curl command line like:
  189. curl -d "user=foobar&pass=12345&id=blablabla&ding=submit" (continues)
  190. http://www.formpost.com/getthis/post.cgi
  191. While -d uses the application/x-www-form-urlencoded mime-type, generally
  192. understood by CGI's and similar, curl also supports the more capable
  193. multipart/form-data type. This latter type supports things like file upload.
  194. -F accepts parameters like -F "name=contents". If you want the contents to
  195. be read from a file, use <@filename> as contents. When specifying a file,
  196. you can also specify the file content type by appending ';type=<mime type>'
  197. to the file name. You can also post the contents of several files in one
  198. field. For example, the field name 'coolfiles' is used to send three files,
  199. with different content types using the following syntax:
  200. curl -F "coolfiles=@fil1.gif;type=image/gif,fil2.txt,fil3.html" \
  201. http://www.post.com/postit.cgi
  202. If the content-type is not specified, curl will try to guess from the file
  203. extension (it only knows a few), or use the previously specified type (from
  204. an earlier file if several files are specified in a list) or else it will
  205. use the default type 'application/octet-stream'.
  206. Emulate a fill-in form with -F. Let's say you fill in three fields in a
  207. form. One field is a file name which to post, one field is your name and one
  208. field is a file description. We want to post the file we have written named
  209. "cooltext.txt". To let curl do the posting of this data instead of your
  210. favourite browser, you have to read the HTML source of the form page and
  211. find the names of the input fields. In our example, the input field names
  212. are 'file', 'yourname' and 'filedescription'.
  213. curl -F "file=@cooltext.txt" -F "yourname=Daniel" \
  214. -F "filedescription=Cool text file with cool text inside" \
  215. http://www.post.com/postit.cgi
  216. To send two files in one post you can do it in two ways:
  217. 1. Send multiple files in a single "field" with a single field name:
  218. curl -F "pictures=@dog.gif,cat.gif"
  219. 2. Send two fields with two field names:
  220. curl -F "docpicture=@dog.gif" -F "catpicture=@cat.gif"
  221. To send a field value literally without interpreting a leading '@'
  222. or '<', or an embedded ';type=', use --form-string instead of
  223. -F. This is recommended when the value is obtained from a user or
  224. some other unpredictable source. Under these circumstances, using
  225. -F instead of --form-string would allow a user to trick curl into
  226. uploading a file.
  227. REFERRER
  228. A HTTP request has the option to include information about which address
  229. that referred to actual page. Curl allows you to specify the
  230. referrer to be used on the command line. It is especially useful to
  231. fool or trick stupid servers or CGI scripts that rely on that information
  232. being available or contain certain data.
  233. curl -e www.coolsite.com http://www.showme.com/
  234. NOTE: The Referer: [sic] field is defined in the HTTP spec to be a full URL.
  235. USER AGENT
  236. A HTTP request has the option to include information about the browser
  237. that generated the request. Curl allows it to be specified on the command
  238. line. It is especially useful to fool or trick stupid servers or CGI
  239. scripts that only accept certain browsers.
  240. Example:
  241. curl -A 'Mozilla/3.0 (Win95; I)' http://www.nationsbank.com/
  242. Other common strings:
  243. 'Mozilla/3.0 (Win95; I)' Netscape Version 3 for Windows 95
  244. 'Mozilla/3.04 (Win95; U)' Netscape Version 3 for Windows 95
  245. 'Mozilla/2.02 (OS/2; U)' Netscape Version 2 for OS/2
  246. 'Mozilla/4.04 [en] (X11; U; AIX 4.2; Nav)' NS for AIX
  247. 'Mozilla/4.05 [en] (X11; U; Linux 2.0.32 i586)' NS for Linux
  248. Note that Internet Explorer tries hard to be compatible in every way:
  249. 'Mozilla/4.0 (compatible; MSIE 4.01; Windows 95)' MSIE for W95
  250. Mozilla is not the only possible User-Agent name:
  251. 'Konqueror/1.0' KDE File Manager desktop client
  252. 'Lynx/2.7.1 libwww-FM/2.14' Lynx command line browser
  253. COOKIES
  254. Cookies are generally used by web servers to keep state information at the
  255. client's side. The server sets cookies by sending a response line in the
  256. headers that looks like 'Set-Cookie: <data>' where the data part then
  257. typically contains a set of NAME=VALUE pairs (separated by semicolons ';'
  258. like "NAME1=VALUE1; NAME2=VALUE2;"). The server can also specify for what
  259. path the "cookie" should be used for (by specifying "path=value"), when the
  260. cookie should expire ("expire=DATE"), for what domain to use it
  261. ("domain=NAME") and if it should be used on secure connections only
  262. ("secure").
  263. If you've received a page from a server that contains a header like:
  264. Set-Cookie: sessionid=boo123; path="/foo";
  265. it means the server wants that first pair passed on when we get anything in
  266. a path beginning with "/foo".
  267. Example, get a page that wants my name passed in a cookie:
  268. curl -b "name=Daniel" www.sillypage.com
  269. Curl also has the ability to use previously received cookies in following
  270. sessions. If you get cookies from a server and store them in a file in a
  271. manner similar to:
  272. curl --dump-header headers www.example.com
  273. ... you can then in a second connect to that (or another) site, use the
  274. cookies from the 'headers' file like:
  275. curl -b headers www.example.com
  276. While saving headers to a file is a working way to store cookies, it is
  277. however error-prone and not the preferred way to do this. Instead, make curl
  278. save the incoming cookies using the well-known netscape cookie format like
  279. this:
  280. curl -c cookies.txt www.example.com
  281. Note that by specifying -b you enable the "cookie awareness" and with -L
  282. you can make curl follow a location: (which often is used in combination
  283. with cookies). So that if a site sends cookies and a location, you can
  284. use a non-existing file to trigger the cookie awareness like:
  285. curl -L -b empty.txt www.example.com
  286. The file to read cookies from must be formatted using plain HTTP headers OR
  287. as netscape's cookie file. Curl will determine what kind it is based on the
  288. file contents. In the above command, curl will parse the header and store
  289. the cookies received from www.example.com. curl will send to the server the
  290. stored cookies which match the request as it follows the location. The
  291. file "empty.txt" may be a nonexistent file.
  292. Alas, to both read and write cookies from a netscape cookie file, you can
  293. set both -b and -c to use the same file:
  294. curl -b cookies.txt -c cookies.txt www.example.com
  295. PROGRESS METER
  296. The progress meter exists to show a user that something actually is
  297. happening. The different fields in the output have the following meaning:
  298. % Total % Received % Xferd Average Speed Time Curr.
  299. Dload Upload Total Current Left Speed
  300. 0 151M 0 38608 0 0 9406 0 4:41:43 0:00:04 4:41:39 9287
  301. From left-to-right:
  302. % - percentage completed of the whole transfer
  303. Total - total size of the whole expected transfer
  304. % - percentage completed of the download
  305. Received - currently downloaded amount of bytes
  306. % - percentage completed of the upload
  307. Xferd - currently uploaded amount of bytes
  308. Average Speed
  309. Dload - the average transfer speed of the download
  310. Average Speed
  311. Upload - the average transfer speed of the upload
  312. Time Total - expected time to complete the operation
  313. Time Current - time passed since the invoke
  314. Time Left - expected time left to completion
  315. Curr.Speed - the average transfer speed the last 5 seconds (the first
  316. 5 seconds of a transfer is based on less time of course.)
  317. The -# option will display a totally different progress bar that doesn't
  318. need much explanation!
  319. SPEED LIMIT
  320. Curl allows the user to set the transfer speed conditions that must be met
  321. to let the transfer keep going. By using the switch -y and -Y you
  322. can make curl abort transfers if the transfer speed is below the specified
  323. lowest limit for a specified time.
  324. To have curl abort the download if the speed is slower than 3000 bytes per
  325. second for 1 minute, run:
  326. curl -Y 3000 -y 60 www.far-away-site.com
  327. This can very well be used in combination with the overall time limit, so
  328. that the above operation must be completed in whole within 30 minutes:
  329. curl -m 1800 -Y 3000 -y 60 www.far-away-site.com
  330. Forcing curl not to transfer data faster than a given rate is also possible,
  331. which might be useful if you're using a limited bandwidth connection and you
  332. don't want your transfer to use all of it (sometimes referred to as
  333. "bandwidth throttle").
  334. Make curl transfer data no faster than 10 kilobytes per second:
  335. curl --limit-rate 10K www.far-away-site.com
  336. or
  337. curl --limit-rate 10240 www.far-away-site.com
  338. Or prevent curl from uploading data faster than 1 megabyte per second:
  339. curl -T upload --limit-rate 1M ftp://uploadshereplease.com
  340. When using the --limit-rate option, the transfer rate is regulated on a
  341. per-second basis, which will cause the total transfer speed to become lower
  342. than the given number. Sometimes of course substantially lower, if your
  343. transfer stalls during periods.
  344. CONFIG FILE
  345. Curl automatically tries to read the .curlrc file (or _curlrc file on win32
  346. systems) from the user's home dir on startup.
  347. The config file could be made up with normal command line switches, but you
  348. can also specify the long options without the dashes to make it more
  349. readable. You can separate the options and the parameter with spaces, or
  350. with = or :. Comments can be used within the file. If the first letter on a
  351. line is a '#'-symbol the rest of the line is treated as a comment.
  352. If you want the parameter to contain spaces, you must enclose the entire
  353. parameter within double quotes ("). Within those quotes, you specify a
  354. quote as \".
  355. NOTE: You must specify options and their arguments on the same line.
  356. Example, set default time out and proxy in a config file:
  357. # We want a 30 minute timeout:
  358. -m 1800
  359. # ... and we use a proxy for all accesses:
  360. proxy = proxy.our.domain.com:8080
  361. White spaces ARE significant at the end of lines, but all white spaces
  362. leading up to the first characters of each line are ignored.
  363. Prevent curl from reading the default file by using -q as the first command
  364. line parameter, like:
  365. curl -q www.thatsite.com
  366. Force curl to get and display a local help page in case it is invoked
  367. without URL by making a config file similar to:
  368. # default url to get
  369. url = "http://help.with.curl.com/curlhelp.html"
  370. You can specify another config file to be read by using the -K/--config
  371. flag. If you set config file name to "-" it'll read the config from stdin,
  372. which can be handy if you want to hide options from being visible in process
  373. tables etc:
  374. echo "user = user:passwd" | curl -K - http://that.secret.site.com
  375. EXTRA HEADERS
  376. When using curl in your own very special programs, you may end up needing
  377. to pass on your own custom headers when getting a web page. You can do
  378. this by using the -H flag.
  379. Example, send the header "X-you-and-me: yes" to the server when getting a
  380. page:
  381. curl -H "X-you-and-me: yes" www.love.com
  382. This can also be useful in case you want curl to send a different text in a
  383. header than it normally does. The -H header you specify then replaces the
  384. header curl would normally send. If you replace an internal header with an
  385. empty one, you prevent that header from being sent. To prevent the Host:
  386. header from being used:
  387. curl -H "Host:" www.server.com
  388. FTP and PATH NAMES
  389. Do note that when getting files with the ftp:// URL, the given path is
  390. relative the directory you enter. To get the file 'README' from your home
  391. directory at your ftp site, do:
  392. curl ftp://user:passwd@my.site.com/README
  393. But if you want the README file from the root directory of that very same
  394. site, you need to specify the absolute file name:
  395. curl ftp://user:passwd@my.site.com//README
  396. (I.e with an extra slash in front of the file name.)
  397. SFTP and SCP and PATH NAMES
  398. With sftp: and scp: URLs, the path name given is the absolute name on the
  399. server. To access a file relative to the remote user's home directory,
  400. prefix the file with /~/ , such as:
  401. curl -u $USER sftp://home.example.com/~/.bashrc
  402. FTP and firewalls
  403. The FTP protocol requires one of the involved parties to open a second
  404. connection as soon as data is about to get transfered. There are two ways to
  405. do this.
  406. The default way for curl is to issue the PASV command which causes the
  407. server to open another port and await another connection performed by the
  408. client. This is good if the client is behind a firewall that don't allow
  409. incoming connections.
  410. curl ftp.download.com
  411. If the server for example, is behind a firewall that don't allow connections
  412. on other ports than 21 (or if it just doesn't support the PASV command), the
  413. other way to do it is to use the PORT command and instruct the server to
  414. connect to the client on the given (as parameters to the PORT command) IP
  415. number and port.
  416. The -P flag to curl supports a few different options. Your machine may have
  417. several IP-addresses and/or network interfaces and curl allows you to select
  418. which of them to use. Default address can also be used:
  419. curl -P - ftp.download.com
  420. Download with PORT but use the IP address of our 'le0' interface (this does
  421. not work on windows):
  422. curl -P le0 ftp.download.com
  423. Download with PORT but use 192.168.0.10 as our IP address to use:
  424. curl -P 192.168.0.10 ftp.download.com
  425. NETWORK INTERFACE
  426. Get a web page from a server using a specified port for the interface:
  427. curl --interface eth0:1 http://www.netscape.com/
  428. or
  429. curl --interface 192.168.1.10 http://www.netscape.com/
  430. HTTPS
  431. Secure HTTP requires SSL libraries to be installed and used when curl is
  432. built. If that is done, curl is capable of retrieving and posting documents
  433. using the HTTPS protocol.
  434. Example:
  435. curl https://www.secure-site.com
  436. Curl is also capable of using your personal certificates to get/post files
  437. from sites that require valid certificates. The only drawback is that the
  438. certificate needs to be in PEM-format. PEM is a standard and open format to
  439. store certificates with, but it is not used by the most commonly used
  440. browsers (Netscape and MSIE both use the so called PKCS#12 format). If you
  441. want curl to use the certificates you use with your (favourite) browser, you
  442. may need to download/compile a converter that can convert your browser's
  443. formatted certificates to PEM formatted ones. This kind of converter is
  444. included in recent versions of OpenSSL, and for older versions Dr Stephen
  445. N. Henson has written a patch for SSLeay that adds this functionality. You
  446. can get his patch (that requires an SSLeay installation) from his site at:
  447. http://www.drh-consultancy.demon.co.uk/
  448. Example on how to automatically retrieve a document using a certificate with
  449. a personal password:
  450. curl -E /path/to/cert.pem:password https://secure.site.com/
  451. If you neglect to specify the password on the command line, you will be
  452. prompted for the correct password before any data can be received.
  453. Many older SSL-servers have problems with SSLv3 or TLS, that newer versions
  454. of OpenSSL etc is using, therefore it is sometimes useful to specify what
  455. SSL-version curl should use. Use -3, -2 or -1 to specify that exact SSL
  456. version to use (for SSLv3, SSLv2 or TLSv1 respectively):
  457. curl -2 https://secure.site.com/
  458. Otherwise, curl will first attempt to use v3 and then v2.
  459. To use OpenSSL to convert your favourite browser's certificate into a PEM
  460. formatted one that curl can use, do something like this (assuming netscape,
  461. but IE is likely to work similarly):
  462. You start with hitting the 'security' menu button in netscape.
  463. Select 'certificates->yours' and then pick a certificate in the list
  464. Press the 'export' button
  465. enter your PIN code for the certs
  466. select a proper place to save it
  467. Run the 'openssl' application to convert the certificate. If you cd to the
  468. openssl installation, you can do it like:
  469. # ./apps/openssl pkcs12 -in [file you saved] -clcerts -out [PEMfile]
  470. RESUMING FILE TRANSFERS
  471. To continue a file transfer where it was previously aborted, curl supports
  472. resume on http(s) downloads as well as ftp uploads and downloads.
  473. Continue downloading a document:
  474. curl -C - -o file ftp://ftp.server.com/path/file
  475. Continue uploading a document(*1):
  476. curl -C - -T file ftp://ftp.server.com/path/file
  477. Continue downloading a document from a web server(*2):
  478. curl -C - -o file http://www.server.com/
  479. (*1) = This requires that the ftp server supports the non-standard command
  480. SIZE. If it doesn't, curl will say so.
  481. (*2) = This requires that the web server supports at least HTTP/1.1. If it
  482. doesn't, curl will say so.
  483. TIME CONDITIONS
  484. HTTP allows a client to specify a time condition for the document it
  485. requests. It is If-Modified-Since or If-Unmodified-Since. Curl allow you to
  486. specify them with the -z/--time-cond flag.
  487. For example, you can easily make a download that only gets performed if the
  488. remote file is newer than a local copy. It would be made like:
  489. curl -z local.html http://remote.server.com/remote.html
  490. Or you can download a file only if the local file is newer than the remote
  491. one. Do this by prepending the date string with a '-', as in:
  492. curl -z -local.html http://remote.server.com/remote.html
  493. You can specify a "free text" date as condition. Tell curl to only download
  494. the file if it was updated since January 12, 2012:
  495. curl -z "Jan 12 2012" http://remote.server.com/remote.html
  496. Curl will then accept a wide range of date formats. You always make the date
  497. check the other way around by prepending it with a dash '-'.
  498. DICT
  499. For fun try
  500. curl dict://dict.org/m:curl
  501. curl dict://dict.org/d:heisenbug:jargon
  502. curl dict://dict.org/d:daniel:web1913
  503. Aliases for 'm' are 'match' and 'find', and aliases for 'd' are 'define'
  504. and 'lookup'. For example,
  505. curl dict://dict.org/find:curl
  506. Commands that break the URL description of the RFC (but not the DICT
  507. protocol) are
  508. curl dict://dict.org/show:db
  509. curl dict://dict.org/show:strat
  510. Authentication is still missing (but this is not required by the RFC)
  511. LDAP
  512. If you have installed the OpenLDAP library, curl can take advantage of it
  513. and offer ldap:// support.
  514. LDAP is a complex thing and writing an LDAP query is not an easy task. I do
  515. advice you to dig up the syntax description for that elsewhere. Two places
  516. that might suit you are:
  517. Netscape's "Netscape Directory SDK 3.0 for C Programmer's Guide Chapter 10:
  518. Working with LDAP URLs":
  519. http://developer.netscape.com/docs/manuals/dirsdk/csdk30/url.htm
  520. RFC 2255, "The LDAP URL Format" http://curl.haxx.se/rfc/rfc2255.txt
  521. To show you an example, this is now I can get all people from my local LDAP
  522. server that has a certain sub-domain in their email address:
  523. curl -B "ldap://ldap.frontec.se/o=frontec??sub?mail=*sth.frontec.se"
  524. If I want the same info in HTML format, I can get it by not using the -B
  525. (enforce ASCII) flag.
  526. ENVIRONMENT VARIABLES
  527. Curl reads and understands the following environment variables:
  528. http_proxy, HTTPS_PROXY, FTP_PROXY
  529. They should be set for protocol-specific proxies. General proxy should be
  530. set with
  531. ALL_PROXY
  532. A comma-separated list of host names that shouldn't go through any proxy is
  533. set in (only an asterisk, '*' matches all hosts)
  534. NO_PROXY
  535. If the host name matches one of these strings, or the host is within the
  536. domain of one of these strings, transactions with that node will not be
  537. proxied.
  538. The usage of the -x/--proxy flag overrides the environment variables.
  539. NETRC
  540. Unix introduced the .netrc concept a long time ago. It is a way for a user
  541. to specify name and password for commonly visited ftp sites in a file so
  542. that you don't have to type them in each time you visit those sites. You
  543. realize this is a big security risk if someone else gets hold of your
  544. passwords, so therefore most unix programs won't read this file unless it is
  545. only readable by yourself (curl doesn't care though).
  546. Curl supports .netrc files if told so (using the -n/--netrc and
  547. --netrc-optional options). This is not restricted to only ftp,
  548. but curl can use it for all protocols where authentication is used.
  549. A very simple .netrc file could look something like:
  550. machine curl.haxx.se login iamdaniel password mysecret
  551. CUSTOM OUTPUT
  552. To better allow script programmers to get to know about the progress of
  553. curl, the -w/--write-out option was introduced. Using this, you can specify
  554. what information from the previous transfer you want to extract.
  555. To display the amount of bytes downloaded together with some text and an
  556. ending newline:
  557. curl -w 'We downloaded %{size_download} bytes\n' www.download.com
  558. KERBEROS FTP TRANSFER
  559. Curl supports kerberos4 and kerberos5/GSSAPI for FTP transfers. You need
  560. the kerberos package installed and used at curl build time for it to be
  561. used.
  562. First, get the krb-ticket the normal way, like with the kinit/kauth tool.
  563. Then use curl in way similar to:
  564. curl --krb private ftp://krb4site.com -u username:fakepwd
  565. There's no use for a password on the -u switch, but a blank one will make
  566. curl ask for one and you already entered the real password to kinit/kauth.
  567. TELNET
  568. The curl telnet support is basic and very easy to use. Curl passes all data
  569. passed to it on stdin to the remote server. Connect to a remote telnet
  570. server using a command line similar to:
  571. curl telnet://remote.server.com
  572. And enter the data to pass to the server on stdin. The result will be sent
  573. to stdout or to the file you specify with -o.
  574. You might want the -N/--no-buffer option to switch off the buffered output
  575. for slow connections or similar.
  576. Pass options to the telnet protocol negotiation, by using the -t option. To
  577. tell the server we use a vt100 terminal, try something like:
  578. curl -tTTYPE=vt100 telnet://remote.server.com
  579. Other interesting options for it -t include:
  580. - XDISPLOC=<X display> Sets the X display location.
  581. - NEW_ENV=<var,val> Sets an environment variable.
  582. NOTE: the telnet protocol does not specify any way to login with a specified
  583. user and password so curl can't do that automatically. To do that, you need
  584. to track when the login prompt is received and send the username and
  585. password accordingly.
  586. PERSISTENT CONNECTIONS
  587. Specifying multiple files on a single command line will make curl transfer
  588. all of them, one after the other in the specified order.
  589. libcurl will attempt to use persistent connections for the transfers so that
  590. the second transfer to the same host can use the same connection that was
  591. already initiated and was left open in the previous transfer. This greatly
  592. decreases connection time for all but the first transfer and it makes a far
  593. better use of the network.
  594. Note that curl cannot use persistent connections for transfers that are used
  595. in subsequence curl invokes. Try to stuff as many URLs as possible on the
  596. same command line if they are using the same host, as that'll make the
  597. transfers faster. If you use a http proxy for file transfers, practically
  598. all transfers will be persistent.
  599. MULTIPLE TRANSFERS WITH A SINGLE COMMAND LINE
  600. As is mentioned above, you can download multiple files with one command line
  601. by simply adding more URLs. If you want those to get saved to a local file
  602. instead of just printed to stdout, you need to add one save option for each
  603. URL you specify. Note that this also goes for the -O option (but not
  604. --remote-name-all).
  605. For example: get two files and use -O for the first and a custom file
  606. name for the second:
  607. curl -O http://url.com/file.txt ftp://ftp.com/moo.exe -o moo.jpg
  608. You can also upload multiple files in a similar fashion:
  609. curl -T local1 ftp://ftp.com/moo.exe -T local2 ftp://ftp.com/moo2.txt
  610. IPv6
  611. curl will connect to a server with IPv6 when a host lookup returns an IPv6
  612. address and fall back to IPv4 if the connection fails. The --ipv4 and --ipv6
  613. options can specify which address to use when both are available. IPv6
  614. addresses can also be specified directly in URLs using the syntax:
  615. http://[2001:1890:1112:1::20]/overview.html
  616. When this style is used, the -g option must be given to stop curl from
  617. interpreting the square brackets as special globbing characters. Link local
  618. and site local addresses including a scope identifier, such as fe80::1234%1,
  619. may also be used, but the scope portion must be numeric and the percent
  620. character must be URL escaped. The previous example in an SFTP URL might
  621. look like:
  622. sftp://[fe80::1234%251]/
  623. IPv6 addresses provided other than in URLs (e.g. to the --proxy, --interface
  624. or --ftp-port options) should not be URL encoded.
  625. MAILING LISTS
  626. For your convenience, we have several open mailing lists to discuss curl,
  627. its development and things relevant to this. Get all info at
  628. http://curl.haxx.se/mail/. Some of the lists available are:
  629. curl-users
  630. Users of the command line tool. How to use it, what doesn't work, new
  631. features, related tools, questions, news, installations, compilations,
  632. running, porting etc.
  633. curl-library
  634. Developers using or developing libcurl. Bugs, extensions, improvements.
  635. curl-announce
  636. Low-traffic. Only receives announcements of new public versions. At worst,
  637. that makes something like one or two mails per month, but usually only one
  638. mail every second month.
  639. curl-and-php
  640. Using the curl functions in PHP. Everything curl with a PHP angle. Or PHP
  641. with a curl angle.
  642. curl-and-python
  643. Python hackers using curl with or without the python binding pycurl.
  644. Please direct curl questions, feature requests and trouble reports to one of
  645. these mailing lists instead of mailing any individual.