MANUAL 39 KB

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