MANUAL 38 KB

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