{"id":196,"date":"2016-01-12T15:34:27","date_gmt":"2016-01-12T15:34:27","guid":{"rendered":"http:\/\/wp-p3d2tsa2xh.pairsite.com\/?p=196"},"modified":"2025-05-21T14:47:33","modified_gmt":"2025-05-21T18:47:33","slug":"paircloud-downloading-files-with-curl","status":"publish","type":"ht_kb","link":"https:\/\/www.pair.com\/support\/kb\/paircloud-downloading-files-with-curl\/","title":{"rendered":"Downloading files with curl"},"content":{"rendered":"<p class=\"p1\"><span class=\"s1\"><a style=\"color:#fff; text-decoration:none!important;\" href=\"https:\/\/www.pair.com\/support\/kb\/tags\/shared-hosting\/\"><p style=\"background-color:#1a3d6e !important;color:#fff;padding:6px; display:inline-block!important;font-size:12px;font-weight:bold; border-radius:3px;\">Shared<\/p><\/a> <a style=\"color:#fff; text-decoration:none!important;\" href=\"https:\/\/www.pair.com\/support\/kb\/tags\/vps\/\"><p style=\"background-color:#1a3d6e !important;color:#fff;padding:6px; display:inline-block!important;font-size:12px;font-weight:bold; border-radius:3px;\">VPS<\/p><\/a> <a style=\"color:#fff; text-decoration:none!important;\" href=\"https:\/\/www.pair.com\/support\/kb\/tags\/qs-dedicated\/\"><p style=\"background-color:#1a3d6e !important;color:#fff;padding:6px; display:inline-block!important;font-size:12px; font-weight:bold; border-radius:3px;\">Dedicated<\/p><\/a>&nbsp;<a style=\"color:#fff; text-decoration:none!important;\" href=\"https:\/\/www.pair.com\/support\/kb\/tags\/wp-professional\/\"><p style=\"background-color:#1a3d6e !important;color:#fff !important;padding:6px; display:inline-block!important;font-size:12px;font-weight:bold; border-radius:3px;\">WP Professional<\/p><\/a> <a style=\"color:#fff; text-decoration:none!important;\" href=\"https:\/\/www.pair.com\/support\/kb\/tags\/wp-professional-plus\/\"><p style=\"background-color:#1a3d6e !important;color:#fff !important;padding:6px; display:inline-block!important;font-size:12px;font-weight:bold; border-radius:3px;\">WP Professional Plus<\/p><\/a><\/span><\/p>\n<p>cURL is both a library and a command line utility written to handle the transfer of data using many different protocols. It is scriptable and extremely versatile but this makes it quite complicated.<\/p>\n<p>If you are looking for a utility to download a file then please see wget. We would recommend reading our wget tutorial first and checking out <code>man wget<\/code> before using curl as wget is more user-friendly in most cases. However, for more complex operations you cannot beat cURL. It has over 100 different command line options many of which can be used in combinations. It is very powerful and can even handle cookies, forms and ssl. However it can also be used for some very simple tasks that you will find useful. In this tutorial we will concentrate on the things that cURL can do that wget can\u2019t.<\/p>\n<h3 class=\"kb\">The Basics<\/h3>\n<p>At its most basic you can use cURL to download a file from a remote server. To download the homepage of <code>example.com<\/code> you would use <code>curl example.com<\/code>. cURL can use many different protocols but defaults to HTTP if none is provided. It will, however, try other protocols as well and it can intelligently guess which protocol to use if hints are given. For instance, if you use <code>curl ftp.example.com<\/code> it will automatically try the FTP:\/\/ protocol.<\/p>\n<p>If however you want to help cURL to choose the right protocol then prefix the url with the protocol such as <code>curl http:\/\/example.com<\/code> or <code>curl ftp:\/\/example.com<\/code>.<\/p>\n<h3 class=\"kb\">Setting the output file<\/h3>\n<p>If you want to give the downloaded file a different name you would use the -o option. For example.<code>curl -o filename.tar.gz http:\/\/filename-4.0.1.tar.gz<\/code><\/p>\n<p>If you don\u2019t set the output file it will display it to the console.<\/p>\n<h3 class=\"kb\">Viewing the complete request and response<\/h3>\n<p>Quite often when learning curl you will either get an unexpected output or no output at all. The <code>-v<\/code> option is very useful in these situations. The <code>-v<\/code> option displays all the information in the request sent to the remote server and the response it receives.<\/p>\n<h3 class=\"kb\">Saving a 301-redirected file<\/h3>\n<p>If a site has WordPress\u00ae installed for example and they are using 301 redirects you will by default download the redirect response only. To ensure you follow the redirects and get the final file you will need to use the -L option. If you try <code>curl google.com<\/code> you will just get the redirect page, if you now try <code>curl -L google.com<\/code> you will get the page you were after.<\/p>\n<div class=\"bs-callout bs-callout-info\">\n<h4 class=\"text-info\">Nothing returned<\/h4>\n<p>If you use curl and don\u2019t get any return or an error you can try the -v option. This will show all the headers. The header may have a 301 redirect code in it but no body to display. If this is the case you can use the -L option to follow the redirect.<\/p>\n<\/div>\n<p>Those are the basics of cURL. We will now move on to the intermediate levels of cURL usage.<\/p>\n<h3 class=\"kb\">Viewing only the response headers for debugging<\/h3>\n<p>When you are writing a script using cURL sometimes you will want to view the response headers only without seeing the data or the request. Having a clean view of what is happening, without all the data to obscure things, can be helpful with debugging. To do this you would use the <code>-I<\/code> option. For instance in the previous example with Google\u00ae we could use <code>curl -I google.com<\/code><\/p>\n<h3 class=\"kb\">Skipping SSL checks<\/h3>\n<p>When connecting to a remote server that has a self signed certificate you will want to skip the ssl checks. To do this use the <code>-k<\/code> option. For example <code>curl -k https:\/\/google.com<\/code><\/p>\n<h3 class=\"kb\">Setting the user agent<\/h3>\n<p>The <code>-A<\/code> option allows you to set the user agent. For example <code>curl -A \"Mozilla\/5.0 (Windows NT 6.3; WOW64; rv:40.0) Gecko\/20100101 Firefox\/40.0\" -L google.com<\/code>.<\/p>\n<h3 class=\"kb\">Rate Limiting<\/h3>\n<p>To avoid hitting the remote server hard you can limit the download rate you will use. The command to do this is <code>--limit-rate<\/code> and use like this <code>--limit-rate 100k<\/code>.<\/p>\n<h3 class=\"kb\">FTP Login<\/h3>\n<p>To set the username and password you can use the \u2013user username:password option.<\/p>\n<h3 class=\"kb\">FTP upload and download<\/h3>\n<p>To download you just need to use the basic curl command but add your username and password like this <code>curl --user username:password -o filename.tar.gz ftp:\/\/domain.com\/directory\/filename.tar.gz <\/code>.<\/p>\n<p>To upload you need to use both the \u2013user option and the -T option as follows.<br \/>\n<code>curl --user username:password -T filename.tar.g ftp:\/\/domain.com\/directory\/ <\/code><\/p>\n<p>To delete a file from the remote server.<br \/>\n<code>curl --user username:password -X 'DELE filename.tar.gz' ftp:\/\/domain.com\/ <\/code><\/p>\n<p>For details on the <code>-X<\/code> option please see the next section.<\/p>\n<h3 class=\"kb\">Sending POST requests and different FTP Commands<\/h3>\n<p>The -X command allows you to send custom commands to the receiving server. For HTTP this could be a POST request or WebDAV\u2019s copy or move. For FTP you can use the <code>-X<\/code> option to send other commands instead of the default file LIST, like in the previous section's example of using <code>-X<\/code> to send the DELE command to an FTP server. However, this can also be used to send full POST data to an HTTP server.<\/p>\n<p>If the page you wanted to POST to had a form like this:<\/p>\n<pre>&lt;form action=\"test.php\" method=\"POST\"&gt;\n  &lt;input name=\"Name\" type=\"text\" \/&gt; \n  &lt;input name=\"button1\" type=\"submit\" value=\"OK\" \/&gt;\n&lt;\/form&gt;<\/pre>\n<p>you could submit the form request using <code>curl -X POST --data \"name=barrym&amp;button1=OK\" http:\/\/www.example.com\/test.php<\/code>.<\/p>\n<h3 class=\"kb\">Using Cookies<\/h3>\n<p>If the server you are connecting to requires a cookie then you can send it using <code>curl -b cookiefile.txt http:\/\/example.com<\/code><\/p>\n<h3 class=\"kb\">Sending custom headers<\/h3>\n<p>If you need to send a custom header to the server you would use the <code>-H<\/code> option like this<br \/>\n<code>curl -H \"Accept: text\/html\" http:\/\/domain.com<\/code>. Which would set the content type to text\/html.<\/p>\n<h3 class=\"kb\">Verifying an SSL Certificate<\/h3>\n<p>If you want to verify that your SSL cert is valid without using your browser and run into potential caching issues then use <code>curl --cacert mycert.crt https:\/\/domain.com<\/code>. This is also useful if you need to validate the connection to ensure that you are connecting to the right server.<\/p>\n<p>The certificate must be in PEM format. If the optional password is not specified, it will be queried for on the terminal. Note that this option assumes a \u201ccertificate\u201d file that is the private key and the private certificate concatenated.<\/p>\n<h3 class=\"kb\">Limiting the connection timeout time<\/h3>\n<p>Sometimes you will want the connection to time out quickly if it can\u2019t make the connection within a certain time frame. The option to use to do this is \u2013connect-timeout. This only affects the connection time so once you are connected it no longer applies. <code>curl --connect-timeout 5 http:\/\/domain.com<\/code><\/p>\n<h3 class=\"kb\">Finding out more<\/h3>\n<p>As stated in the introduction there are over 100 command line options for cURL so we have just covered some of the most commonly used ones in our experiences. cURL can do a lot more than described above and <code>man curl<\/code> is a good place to start to find out more. If you prefer a web-based reference then <a href=\"http:\/\/curl.haxx.se\/docs\/faq.html\" target=\"_blank\" rel=\"noopener\">http:\/\/curl.haxx.se\/docs\/faq.html<\/a> is the authoritative one.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp; cURL is both a library and a command line utility written to handle the transfer of data using many different protocols. It is scriptable and extremely versatile but this makes it quite complicated. If you are looking for a utility to download a file then please see wget. We&#8230;<\/p>\n","protected":false},"author":12,"comment_status":"closed","ping_status":"open","template":"","format":"standard","meta":[],"ht-kb-category":[13],"ht-kb-tag":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v21.8.1 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>cURL Download | Downloading Files With cURL | cURL FTP<\/title>\n<meta name=\"description\" content=\"cURL is a library and a command line utility that transfers data using different protocols. Use the cURL command to download a file with username and password.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.pair.com\/support\/kb\/paircloud-downloading-files-with-curl\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"cURL Download | Downloading Files With cURL | cURL FTP\" \/>\n<meta property=\"og:description\" content=\"cURL is a library and a command line utility that transfers data using different protocols. Use the cURL command to download a file with username and password.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.pair.com\/support\/kb\/paircloud-downloading-files-with-curl\/\" \/>\n<meta property=\"og:site_name\" content=\"Knowledge Base - Pair Networks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/pairnetworks\/\" \/>\n<meta property=\"article:modified_time\" content=\"2025-05-21T18:47:33+00:00\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:site\" content=\"@pairNetworks\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"5 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.pair.com\/support\/kb\/paircloud-downloading-files-with-curl\/\",\"url\":\"https:\/\/www.pair.com\/support\/kb\/paircloud-downloading-files-with-curl\/\",\"name\":\"cURL Download | Downloading Files With cURL | cURL FTP\",\"isPartOf\":{\"@id\":\"https:\/\/www.pair.com\/support\/kb\/#website\"},\"datePublished\":\"2016-01-12T15:34:27+00:00\",\"dateModified\":\"2025-05-21T18:47:33+00:00\",\"description\":\"cURL is a library and a command line utility that transfers data using different protocols. Use the cURL command to download a file with username and password.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.pair.com\/support\/kb\/paircloud-downloading-files-with-curl\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.pair.com\/support\/kb\/paircloud-downloading-files-with-curl\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.pair.com\/support\/kb\/paircloud-downloading-files-with-curl\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.pair.com\/support\/kb\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Downloading files with curl\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.pair.com\/support\/kb\/#website\",\"url\":\"https:\/\/www.pair.com\/support\/kb\/\",\"name\":\"Knowledge Base - Pair Networks\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/www.pair.com\/support\/kb\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.pair.com\/support\/kb\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.pair.com\/support\/kb\/#organization\",\"name\":\"Pair Networks\",\"url\":\"https:\/\/www.pair.com\/support\/kb\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.pair.com\/support\/kb\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.pair.com\/support\/kb\/wp-content\/uploads\/2022\/02\/Gb_TUkUE_400x400.jpeg\",\"contentUrl\":\"https:\/\/www.pair.com\/support\/kb\/wp-content\/uploads\/2022\/02\/Gb_TUkUE_400x400.jpeg\",\"width\":360,\"height\":360,\"caption\":\"Pair Networks\"},\"image\":{\"@id\":\"https:\/\/www.pair.com\/support\/kb\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/pairnetworks\/\",\"https:\/\/twitter.com\/pairNetworks\",\"https:\/\/www.instagram.com\/pairnetworks\/\",\"https:\/\/www.linkedin.com\/company\/2269676\/\",\"https:\/\/www.pinterest.com\/pairnetworksinc\/pins\/\",\"https:\/\/www.youtube.com\/user\/pairnetworks\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"cURL Download | Downloading Files With cURL | cURL FTP","description":"cURL is a library and a command line utility that transfers data using different protocols. Use the cURL command to download a file with username and password.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.pair.com\/support\/kb\/paircloud-downloading-files-with-curl\/","og_locale":"en_US","og_type":"article","og_title":"cURL Download | Downloading Files With cURL | cURL FTP","og_description":"cURL is a library and a command line utility that transfers data using different protocols. Use the cURL command to download a file with username and password.","og_url":"https:\/\/www.pair.com\/support\/kb\/paircloud-downloading-files-with-curl\/","og_site_name":"Knowledge Base - Pair Networks","article_publisher":"https:\/\/www.facebook.com\/pairnetworks\/","article_modified_time":"2025-05-21T18:47:33+00:00","twitter_card":"summary_large_image","twitter_site":"@pairNetworks","twitter_misc":{"Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.pair.com\/support\/kb\/paircloud-downloading-files-with-curl\/","url":"https:\/\/www.pair.com\/support\/kb\/paircloud-downloading-files-with-curl\/","name":"cURL Download | Downloading Files With cURL | cURL FTP","isPartOf":{"@id":"https:\/\/www.pair.com\/support\/kb\/#website"},"datePublished":"2016-01-12T15:34:27+00:00","dateModified":"2025-05-21T18:47:33+00:00","description":"cURL is a library and a command line utility that transfers data using different protocols. Use the cURL command to download a file with username and password.","breadcrumb":{"@id":"https:\/\/www.pair.com\/support\/kb\/paircloud-downloading-files-with-curl\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.pair.com\/support\/kb\/paircloud-downloading-files-with-curl\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.pair.com\/support\/kb\/paircloud-downloading-files-with-curl\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.pair.com\/support\/kb\/"},{"@type":"ListItem","position":2,"name":"Downloading files with curl"}]},{"@type":"WebSite","@id":"https:\/\/www.pair.com\/support\/kb\/#website","url":"https:\/\/www.pair.com\/support\/kb\/","name":"Knowledge Base - Pair Networks","description":"","publisher":{"@id":"https:\/\/www.pair.com\/support\/kb\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.pair.com\/support\/kb\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.pair.com\/support\/kb\/#organization","name":"Pair Networks","url":"https:\/\/www.pair.com\/support\/kb\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.pair.com\/support\/kb\/#\/schema\/logo\/image\/","url":"https:\/\/www.pair.com\/support\/kb\/wp-content\/uploads\/2022\/02\/Gb_TUkUE_400x400.jpeg","contentUrl":"https:\/\/www.pair.com\/support\/kb\/wp-content\/uploads\/2022\/02\/Gb_TUkUE_400x400.jpeg","width":360,"height":360,"caption":"Pair Networks"},"image":{"@id":"https:\/\/www.pair.com\/support\/kb\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/pairnetworks\/","https:\/\/twitter.com\/pairNetworks","https:\/\/www.instagram.com\/pairnetworks\/","https:\/\/www.linkedin.com\/company\/2269676\/","https:\/\/www.pinterest.com\/pairnetworksinc\/pins\/","https:\/\/www.youtube.com\/user\/pairnetworks"]}]}},"_links":{"self":[{"href":"https:\/\/www.pair.com\/support\/kb\/wp-json\/wp\/v2\/ht-kb\/196"}],"collection":[{"href":"https:\/\/www.pair.com\/support\/kb\/wp-json\/wp\/v2\/ht-kb"}],"about":[{"href":"https:\/\/www.pair.com\/support\/kb\/wp-json\/wp\/v2\/types\/ht_kb"}],"author":[{"embeddable":true,"href":"https:\/\/www.pair.com\/support\/kb\/wp-json\/wp\/v2\/users\/12"}],"replies":[{"embeddable":true,"href":"https:\/\/www.pair.com\/support\/kb\/wp-json\/wp\/v2\/comments?post=196"}],"version-history":[{"count":5,"href":"https:\/\/www.pair.com\/support\/kb\/wp-json\/wp\/v2\/ht-kb\/196\/revisions"}],"predecessor-version":[{"id":9802,"href":"https:\/\/www.pair.com\/support\/kb\/wp-json\/wp\/v2\/ht-kb\/196\/revisions\/9802"}],"wp:attachment":[{"href":"https:\/\/www.pair.com\/support\/kb\/wp-json\/wp\/v2\/media?parent=196"}],"wp:term":[{"taxonomy":"ht_kb_category","embeddable":true,"href":"https:\/\/www.pair.com\/support\/kb\/wp-json\/wp\/v2\/ht-kb-category?post=196"},{"taxonomy":"ht_kb_tag","embeddable":true,"href":"https:\/\/www.pair.com\/support\/kb\/wp-json\/wp\/v2\/ht-kb-tag?post=196"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}