How to download a file from WebDAV using cURL
This article explains how to download a file from a WebDAV server using cURL from the command line. The command below will perform an HTTP GET request to fetch the file in one step.
This article is geared toward BigCommerce/SabreDAV WebDAV servers, which use message digest HTTP authentication. You can select an alternate authentication method depending on your server type. cURL natively supports Basic, GSSNegotiate, NTML, and message digest authentication. It can also auto-detect the authentication method if you are not sure.
cURL WebDAV Example GET
curl --digest --user username:password https://store-12345.mybigcommerce.com/dav/exports/products-2012-10-05.csv --output products-2012-10-05.csv
The above command is wrapped for readability. Here is an explanation of each command-line option:
- Select message digest HTTP authentication
- --user username:password
- The username and password to the server. This user must have WebDAV access enabled from the BigCommerce Users Control Panel.
- The complete URL to the file to be downloaded.
- --output products-2012-10-05.csv
- The name of the file where the output should be saved.
You can optionally add the following useful command line parameters for cURL:
- Do not show progress meter or error messages
- --request PROPFIND
- Get the properties of the file, like last modified date, file size, existence, and content type. This information is returned in XML format according to the WebDAV Specifications for PROPFIND.
PHP cURL Options
You can also use PHP cURL to fetch the file from WebDAV easily. Just do a normal GET request with the following custom cURL options:
- CURLOPT_HTTPAUTH => CURLAUTH_DIGEST
- Use message-digest HTTP authentication
- CURLOPT_USERPWD => "username:password"
- Specify the username and password to authenticate to the WebDAV server.
Disclaimer: This content is provided as-is. The information may be incorrect.