Note: dotCMS WebDAV support is now deprecated in favor of the dotCMS CLI.
Web-based Distributed Authoring and Versioning, or WebDAV, is an extension of the HTTP protocol that allows you to create a connection between your local computer and a server to easily transfer files between machines. For WebDav the command line tool Curl is used to manipulate files on the server.
To learn how to install WebDav take a look at Upload via WebDav.
When working with WebDAV, we recommend using Cyberduck — particularly in a Windows environment, as Windows support for WebDAV was announced as deprecated in November 2023.
Basic WebDAV Commands
There are four basic commands in Curl for WebDAV, Reading, Deleting, Renaming and Uploading.
Reading Files and Folders
WebDAV uses the Curl get command to reading files or folders. The get in Curl is implied so our command would look like:
curl 'https://demo.dotcms.com/webdav/live/1/demo.dotcms.com'
In dotCMS the url pattern is {server}/webdav/{live or working}/{languageid}/{site path}
If you are looking to get a response see Get Response Code.
Deleting Files and Folders
The -X DELETE
command is used to delete an existing file or folder at the path specified.
To delete a folder:
curl -X DELETE 'https://demo.dotcms.com/webdav/live/1/test'
To delete a file:
curl -X DELETE 'https://demo.dotcms.com/webdav/live/1/test.txt'
Renaming Files
To rename a file we use the Curl -X MOVE
command because we are essentially creating a new file with the new name moving the contents of the old file to the new one and then deleting the file.
curl -X MOVE --header
'Destination: https://demo.dotcms.com/webdav/live/1/new.txt'
'https://demo.dotcms.com/webdav/live/1/old.txt'
Creating New Folder
Use -X MKCOL
to make a new directory:
curl -X MKCOL 'https://demo.dotcms.com/webdav/live/1/new_folder'
Uploading Files
The put command is used for uploading a file to WebDAV
curl -T '/path/to/local/file.txt' 'https://demo.dotcms.com/webdav/live/1/test'
In this example file.txt
which is located at /path/to/local
is being uploaded to our folder on WebDAV test
Curl –Options
Curl provides many useful options to enhance the basic calls.
Setting a Username and Password
To set a username and password for WebDav in curl use the following command:
curl --user 'userName:pass' 'https://demo.dotcms.com/webdav/live/1'
In this example userName
is our chosen username and pass
is the password to be set.
HTTP Authentication
To utilize your username and password set above you use authentication. There are three main option commands for authentication in Curl --basic
, --digest
, and --anyauth
.
--anyauth
chooses which authentication type is best for your situation between --basic
and --digest
. Even though you can choose manually which authentication you would like to use --anyauth
is the recommended way to do authentication, especially for those new to Curl and WebDAV.
Below show all three authentication commands
curl --user 'user:pass' 'https://demo.dotcms.com/webdav/live/1' --basic
curl --user 'user:pass' 'https://demo.dotcms.com/webdav/live/1' --digest
curl --user 'user:pass' 'https://demo.dotcms.com/webdav/live/1' --anyauth
Get Response Code
Often in WebDAV you will want a response to know if the request was preformed. One option to know if the request was completed is to use the -sw option:
curl --user 'user:pass' -X DELETE 'https://demo.dotcms.com/webdav/live/1/test' -sw '%{http_code}'