Skip to content

Instantly share code, notes, and snippets.

@gdm
Created February 18, 2018 23:02
Show Gist options
  • Select an option

  • Save gdm/dec87e5d3b8950278b135c5744c4c067 to your computer and use it in GitHub Desktop.

Select an option

Save gdm/dec87e5d3b8950278b135c5744c4c067 to your computer and use it in GitHub Desktop.
Uploads all files and folders recursively to the WebDAV folder passed in the url
#!/usr/bin/perl
use File::Find;
my $script = "";
sub wanted() {
my $f = $File::Find::name;
if (-f $f) {
$script .= "put '$f'\n";
} else {
$script .= "cd '$target_dir'\n";
$script .= "mkdir '$f'\n";
$script .= "cd '$f'\n"
}
}
my $url = $ARGV[0];
print "URL: $url";
if ($url =~ m#https://.*?(/\S*)#) {
my $target_url = "$0";
my $target_dir = "$1";
find({'wanted'=>\&wanted, 'no_chdir' => 1}, ".");
$pid = open(POUT, "| cadaver $url");
print POUT $script;
print POUT "bye\n";
close POUT;
} else {
print "Usage: davpush.pl https//<hostname>:<port>/<upload path>\n";
print "\n";
print "Uploads all files and folders recursively to the WebDAV folder passed in the url.";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment