Using webDAV and Cadaver with dotCMS

As a developer, one of the most annoying things about dotCMS is how many darn *clicks* it takes to edit anything. There must be an easier way to access files in dotCMS. There is: webDAV and Cadaver. Both of these allow limited access to dotCMS's files: the former through Windows Explorer, the latter through a command line.

Connect to the dotCMS Using webDAV

Look at the Connect to the dotCMS Using webDAV page (for Windows, Mac and Linux). This lets you see webDAV files through your file explorer (Windows Explorer on Windows). But be warned: you can't edit these files in place. Instead, you have to make copies of them, edit them locally, then click and drag the files back to the webDAV directory, replacing the originals. You can bookmark the directories though. Also, you don't see everything - you can't see .dot files for example.

Using autopub vs nonpub 

The URL you use to connect with webDAV can control whether changes you make are automatically published or not. See the below examples.

  • http://example.com/webdav/autopub means files are published as they are uploaded.
  • http://example.com/webdav/nonpub means files uploaded as "working" copies.

Cadaver

Macabre name, but a great tool for command line access to webDAV collections such as dotCMS. It is a *nux tool, but there is Cadaver for Cygwin too! Use it like you use the BSD ftp command line tool - when connected, type ? for a list of the commands you can use.

First thing to do is set up a .netrc file that contains your webDAV credentials.

machine     example.com
login       your-username
password    you-password

Then you can connect to it with the following command:

cadaver -t http://example.com/webdav/autopub/dir/you/want

Replace /dir/you/want with whatever directory path you want to start in. Also note the differences between using /webdav/autopub and /webdav/nonpub as noted above in the Using autopub vs nonpub section.

Transferring files via Cadaver script

Of course, what is life without a script? Here is a script that will make transferring files a lot easier.

#! /bin/bash
# webDavTransfer.sh
if [ "$1" != "-d" ] ; then
   echo Usage $0 -d dest-path files ...
   echo Transfer files from current directory to dest-path in webDAV.
   exit 2
fi
destPath=$2
shift; shift

cadaver -t <<EOF
open http://example.com/webdav/autopub/base-path
cd $destPath
mput $@
quit
EOF

The pre-requisite to using this script is that you have ~.netrc file set up as described above, also copied below.

machine     example.com
login       your-username
password    you-password

This is how to use the script:

cd path/to/local/files
webDavTransfer.sh -d tests/rob *.vtl

The result should be what looks like FTP output, and your files should be transferred.

Don't forget that aliases can make it even easier: 

alias myTransfer='webDavTransfer.sh -d tests/rob'

Then all you need to run is:

myTransfer *.vtl

So you can make an alias for each path you transfer to.

Pages that helped me write this post.

My dotCMS notes.

Comments

Popular Posts