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

I'm facing a rather simple situation, I have to upload, as-is, a big tree of files to a WebDAV server that's reachable over HTTPS. I must start the upload from a linux box with command line only. I can install programs on the box.

I've tried Cadaver but it does not support recursive directory upload.

Do you know of simple tools/scripts to achieve that?


Ok, I found something that did it.

I started from the davpush.pl script that can be found here https://github.com/ptillemans/davpush

Some changes were needed:

  • replace all "dav://" to "https://"
  • add "print POUT "open";" before "print POUT $script;"

Damn, having to hack a perl script to simply upload a directory that's rude. I'm still looking for simple tools/scripts.


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


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.