How to recursively upload a directory to a WebDAV server through HTTPS from the command line?

Here is a quickly hacked shell script that permits to do tha using cadaver:

#!/bin/sh

usage () { echo "$0 <src> <cadaver-args>*" >/dev/stderr; }
error () { echo "$1" >/dev/stderr; usage; exit 1; }

test $# '<' 3 || \
    error "Source and cadaver arguments expected!";

src="$1"; shift;
test -r "$src" || \
    error "Source argument should be a readable file or directory!";

cd "$(dirname "$src")";
src="$(basename "$src")";
root="$(pwd)";
rc="$(mktemp)";
{
    find "$src" '(' -type d -a -readable ')' \
    -printf 'mkcol "%p"\n';
    find "$src" '(' -type f -a -readable ')' \
    -printf 'cd "%h"\nlcd "%h"\n'            \
    -printf 'mput "%f"\n'                    \
    -printf 'cd -\nlcd "'"$root"'"\n';
    echo "quit";
} > "$rc";

cadaver -r "$rc" "$@";
rm -f "$rc";

If it is named davcpy.sh then a command like

davcpy.sh "<local-directories>/<dirname>" "https://<target-website>/<some-directories>/"

allows a recursive copy from

<local-directories>/<dirname>

into a remote one named

<some-directories>/<dirname>

Note that it uses the scripting facility of cadaver to still permit interactive typing of login/passwords. I think it is also robust enough to handle weird file and directory names containing spaces, but I did not test any case like that.


Try gnomevfs-copy:

  • CLI Magic: Using GNOMEvfs to manipulate files
  • man page tells you gnomevfs is deprecated in favor of gvfs
  • gvfs-copy man page. Beware: "The exit value 0 is returned regardless of success or failure."

Edit: gvfs-copy is not recursive. I patched it but yet havi to publish the code. In the meantime, check dave from perldav. It does recursive transfers.

If you don't have fuse disabled, you can try davfs2

If you are not adverse to code your own tool, you could use gvfs and get inspiration from the source code of gvfs-copy

I'm having a similar issue, so I may come back with a better solution


A solution could be Rclone. This is a one way command-line sync program, similar to rsync, that supports WebDAV (amongst others). It can recursively copy a directory, skipping files that exist on the destination. It has some command line options to control sync behaviour, for instance, whether you want target files to be deleted if they are gone from the source. There are packages available for many distros but you can also install and run the plain binary. The first time, you'll need to define a "remote":

rclone config create my-remote webdav \
    url https://my-webdav-server/my-dir/ \
    vendor other \
    user 'onno'  pass 'mypasswd'

After that, you can copy or sync files and dirs:

rclone copy /home/onno/mydir my-remote: