Skip to content

Instantly share code, notes, and snippets.

@tinkernels
Created June 13, 2019 18:01
Show Gist options
  • Save tinkernels/76a6d3368c9c2a65d257249312126c52 to your computer and use it in GitHub Desktop.
Save tinkernels/76a6d3368c9c2a65d257249312126c52 to your computer and use it in GitHub Desktop.
upload or download direcotry at webdav recursively
#!/usr/bin/env bash
usage () {
echo "$0 put <src> <cadaver-args>*" >/dev/stderr;
echo "$0 get [more wget arguments] <url>" >/dev/stderr;
}
error () { echo "$1" >/dev/stderr; usage; exit 1; }
test $# '>' 1 || \
error "at least 2 arguments expected!";
if [ "$1" = get ];then
shift 1;
wget -r -nv -np -nH -R "index.html*" "$@";
elif [ "$1" = put ]; then
src="$2"; shift 2;
test -r "$src" || \
error "Source argument should be a readable file or directory!";
cd "$(dirname "$src")" || exit 1;
src="$(basename "$src")";
rc="$(mktemp -t "davyXXXXXXXXXXXXXXXXXX")";
{
find "$src" -type d | sed 's:\\:\\\\:g' | sed 's:\":\\\":g' | sed 's:^:mput ":g' | sed 's:$:/*":g'
echo "quit";
} > "$rc";
cadaver -r "$rc" "$@";
rm -f "$rc";
else
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment