davpush.pl 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #!/usr/bin/perl
  2. # Copyright 2011 Peter Tillemans
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. # http://www.apache.org/licenses/LICENSE-2.0
  7. # Unless required by applicable law or agreed to in writing, software
  8. # distributed under the License is distributed on an "AS IS" BASIS,
  9. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. # See the License for the specific language governing permissions and
  11. # limitations under the License.
  12. use File::Find;
  13. my $script = "";
  14. my $target_url;
  15. my $target_dir;
  16. sub wanted() {
  17. my $f = $File::Find::name;
  18. if (-f $f) {
  19. $script .= "mput $f\n";
  20. } else {
  21. $script .= "mkdir $f\n";
  22. }
  23. }
  24. my $url = $ARGV[0];
  25. print "URL: $url";
  26. if ($url =~ m#https://.*?(/\S*)#) {
  27. $target_url = "$0";
  28. $target_dir = "$1";
  29. find({'wanted'=>\&wanted, 'no_chdir' => 1}, ".");
  30. $pid = open(POUT, "| cadaver $url");
  31. print POUT $script;
  32. print POUT "bye\n";
  33. close POUT;
  34. } else {
  35. print "Usage: davpush.pl dav://<hostname>:<port>/<upload path>\n";
  36. print "\n";
  37. print "Uploads all files and folders recursively to the WebDAV folder passed in the url.";
  38. }