SYNOPSIS

   # DAV script that connects to a webserver, safely makes
   # a new directory and uploads all html files in
   # the /tmp directory.

   use HTTP::DAV;

   $d = HTTP::DAV->new();
   $url = "http://host.org:8080/dav/";

   $d->credentials(
      -user  => "pcollins",
      -pass  => "mypass",
      -url   => $url,
      -realm => "DAV Realm"
   );

   $d->open( -url => $url )
      or die("Couldn't open $url: " .$d->message . "\n");

   # Make a null lock on newdir
   $d->lock( -url => "$url/newdir", -timeout => "10m" )
      or die "Won't put unless I can lock for 10 minutes\n";

   # Make a new directory
   $d->mkcol( -url => "$url/newdir" )
      or die "Couldn't make newdir at $url\n";

   # Upload multiple files to newdir.
   if ( $d->put( -local => "/tmp/*.html", -url => $url ) ) {
      print "successfully uploaded multiple files to $url\n";
   } else {
      print "put failed: " . $d->message . "\n";
   }

   $d->unlock( -url => $url );

DESCRIPTION

\s-1HTTP::DAV\s0 is a Perl \s-1API\s0 for interacting with and modifying content on webservers using the WebDAV protocol. Now you can \s-1LOCK\s0, \s-1DELETE\s0 and \s-1PUT\s0 files and much more on a DAV-enabled webserver.

\s-1HTTP::DAV\s0 is part of the PerlDAV project hosted at http://www.webdav.org/perldav/ and has the following features:

  • Full \s-1RFC2518\s0 method support. \s-1OPTIONS\s0, \s-1TRACE\s0, \s-1GET\s0, \s-1HEAD\s0, \s-1DELETE\s0, \s-1PUT\s0, \s-1COPY\s0, \s-1MOVE\s0, \s-1PROPFIND\s0, \s-1PROPPATCH\s0, \s-1LOCK\s0, \s-1UNLOCK\s0.

  • A fully object-oriented \s-1API\s0.

  • Recursive \s-1GET\s0 and \s-1PUT\s0 for site backups and other scripted transfers.

  • Transparent lock handling when performing \s-1LOCK/COPY/UNLOCK\s0 sequences.

  • http and https support (https requires the Crypt::SSLeay library). See \s-1INSTALLATION\s0.

  • Basic \s-1AND\s0 Digest authentication support (Digest auth requires the \s-1MD5\s0 library). See \s-1INSTALLATION\s0.

  • \*(C`dave\*(C', a fully-functional ftp-style interface written on top of the \s-1HTTP::DAV\s0 \s-1API\s0 and bundled by default with the \s-1HTTP::DAV\s0 library. (If you've already installed \s-1HTTP::DAV\s0, then dave will also have been installed (probably into /usr/local/bin). You can see it's man page by typing \*(L"perldoc dave\*(R" or going to http://www.webdav.org/perldav/dave/.

  • It is built on top of the popular \s-1LWP\s0 (Library for \s-1WWW\s0 access in Perl). This means that \s-1HTTP::DAV\s0 inherits proxy support, redirect handling, basic (and digest) authorization and many other \s-1HTTP\s0 operations. See \*(C`LWP\*(C' for more information.

  • Popular server support. \s-1HTTP::DAV\s0 has been tested against the following servers: mod_dav, \s-1IIS5\s0, Xythos webfile server and mydocsonline. The library is growing an impressive interoperability suite which also serves as useful \*(L"sample scripts\*(R". See \*(L"make test\*(R" and t/*.

\*(C`HTTP::DAV\*(C' essentially has two \s-1API\s0's, one which is accessed through this module directly (\s-1HTTP::DAV\s0) and is a simple abstraction to the rest of the HTTP::DAV::* Classes. The other interface consists of the HTTP::DAV::* classes which if required allow you to get \*(L"down and dirty\*(R" with your \s-1DAV\s0 and \s-1HTTP\s0 interactions.

The methods provided in \*(C`HTTP::DAV\*(C' should do most of what you want. If, however, you need more control over the client's operations or need more info about the server's responses then you will need to understand the rest of the HTTP::DAV::* interfaces. A good place to start is with the \*(C`HTTP::DAV::Resource\*(C' and \*(C`HTTP::DAV::Response\*(C' documentation.

METHODS

\s-1METHOD\s0 \s-1CALLING:\s0 Named vs Unnamed parameters

You can pass parameters to \*(C`HTTP::DAV\*(C' methods in one of two ways: named or unnamed.

Named parameters provides for a simpler/easier to use interface. A named interface affords more readability and allows the developer to ignore a specific order on the parameters. (named parameters are also case insensitive)

Each argument name is preceded by a dash. Neither case nor order matters in the argument list. -url, -Url, and -URL are all acceptable. In fact, only the first argument needs to begin with a dash. If a dash is present in the first argument, \*(C`HTTP::DAV\*(C' assumes dashes for the subsequent ones.

Each method can also be called with unnamed parameters which often makes sense for methods with only one parameter. But the developer will need to ensure that the parameters are passed in the correct order (as listed in the docs).

Doc: method( -url=>$url, [-depth=>$depth] ) Named: $d->method( -url=>$url, -depth=>$d ); # VALID Named: $d->method( -Depth=>$d, -Url=>$url ); # VALID Named: $d->method( Depth=>$d, Url=>$url ); # INVALID (needs -) Named: $d->method( -Arg2=>$val2 ); # INVALID, ARG1 is not optional Unnamed: $d->method( $val1 ); # VALID Unnamed: $d->method( $val2,$val1 ); # INVALID, ARG1 must come first.

\s-1IMPORTANT\s0 \s-1POINT\s0!!!! If you specify a named parameter first but then forget for the second and third parameters, you \s-1WILL\s0 get weird things happen. E.g. this is bad:

$d->method( -url=>$url, $arg2, $arg3 ); # BAD BAD BAD

\s-1THINGS\s0 \s-1YOU\s0 \s-1NEED\s0 \s-1TO\s0 \s-1KNOW\s0

In all of the methods specified in \*(L"\s-1PUBLIC\s0 \s-1METHODS\s0\*(R" there are some common concepts you'll need to understand:

  • URLs represent an absolute or relative \s-1URI\s0. -url=>"host.org/dav_dir/" # Absolute -url=>"/dav_dir/" # Relative -url=>"file.txt" # Relative You can only use a relative \s-1URL\s0 if you have already \*(L"open\*(R"ed an absolute \s-1URL\s0. The \s-1HTTP::DAV\s0 module now consistently uses the named parameter: \s-1URL\s0. The lower-level HTTP::DAV::Resource interface inconsistently interchanges \s-1URL\s0 and \s-1URI\s0. I'm working to resolve this, in the meantime, you'll just need to remember to use the right one by checking the documentation if you need to mix up your use of both interfaces.

  • \s-1GLOBS\s0 Some methods accept wildcards in the \s-1URL\s0. A wildcard can be used to indicate that the command should perform the command on all Resources that match the wildcard. These wildcards are called \s-1GLOBS\s0. The glob may contain the characters \*(L"*\*(R", \*(L"?\*(R" and the set operator \*(L"[...]\*(R" where ... contains multiple characters ([1t2]) or a range such ([1-5]). For the curious, the glob is converted to a regex and then matched: \*(L"*\*(R" to \*(L".*\*(R", \*(L"?\*(R" to \*(L".\*(R", and the [] is left untouched. It is important to note that globs only operate at the leaf-level. For instance \*(L"/my_dir/*/file.txt\*(R" is not a valid glob. If a glob matches no \s-1URL\s0's the command will fail (which normally means returns 0). Globs are useful in conjunction with \s-1CALLBACKS\s0 to provide feedback as each operation completes. See the documentation for each method to determine whether it supports globbing. Globs are useful for interactive style applications (see the source code for \*(C`dave\*(C' as an example). Example globs: $dav1->delete(-url=>"/my_dir/file[1-3]"); # Matches file1, file2, file3 $dav1->delete(-url=>"/my_dir/file[1-3]*.txt");# Matches file1*.txt,file2*.txt,file3*.txt $dav1->delete(-url=>"/my_dir/*/file.txt"); # Invalid. Can only match at leaf-level

  • \s-1CALLBACKS\s0 Callbacks are used by some methods (primarily get and put) to give the caller some insight as to how the operation is progressing. A callback allows you to define a subroutine as defined below and pass a reference (\&ref) to the method. The rationale behind the callback is that a recursive get/put or an operation against many files (using a \*(C`glob\*(C') can actually take a long time to complete. Example callback: $d->get( -url=>$url, -to=>$to, -callback=>\&mycallback ); Your callback function \s-1MUST\s0 accept arguments as follows:

       sub cat_callback {
          my($status,$mesg,$url,$so_far,$length,$data) = @_;
          ...
       }
    

    The \*(C`status\*(C' argument specifies whether the operation has succeeded (1), failed (0), or is in progress (-1). The \*(C`mesg\*(C' argument is a status message. The status message could contain any string and often contains useful error messages or success messages. The \*(C`url\*(C' the remote \s-1URL\s0. The \*(C`so_far\*(C', \*(C`length\*(C' - these parameters indicate how many bytes have been downloaded and how many we should expect. This is useful for doing \*(L"56% to go\*(R" style-gauges. The \*(C`data\*(C' parameter - is the actual data transferred. The \*(C`cat\*(C' command uses this to print the data to the screen. This value will be empty for \*(C`put\*(C'. See the source code of \*(C`dave\*(C' for a useful sample of how to setup a callback. Note that these arguments are \s-1NOT\s0 named parameters. All error messages set during a \*(L"multi-operation\*(R" request (for instance a recursive get/put) are also retrievable via the \*(C`errors()\*(C' function once the operation has completed. See \*(C`ERROR HANDLING\*(C' for more information.

\s-1PUBLIC\s0 \s-1METHODS\s0

new(\s-1USERAGENT\s0)
new(\s-1USERAGENT\s0, \s-1HEADERS\s0)

Creates a new \*(C`HTTP::DAV\*(C' client $d = HTTP::DAV->new(); The \*(C`-useragent\*(C' parameter allows you to pass your own user agent object and expects an \*(C`HTTP::DAV::UserAgent\*(C' object. See the \*(C`dave\*(C' program for an advanced example of a custom UserAgent that interactively prompts the user for their username and password. The \*(C`-headers\*(C' parameter allows you to specify a list of headers to be sent along with all requests. This can be either a hashref like: { "X-My-Header" => "value", ... } or a HTTP::Headers object.

credentials(\s-1USER\s0,PASS,[\s-1URL\s0],[\s-1REALM\s0])

sets authorization credentials for a \*(C`URL\*(C' and/or \*(C`REALM\*(C'. When the client hits a protected resource it will check these credentials to see if either the \*(C`URL\*(C' or \*(C`REALM\*(C' match the authorization response. Either \*(C`URL\*(C' or \*(C`REALM\*(C' must be provided. returns no value Example: $d->credentials( -url=>'myhost.org:8080/test/', -user=>'pcollins', -pass=>'mypass');

DebugLevel($val)

sets the debug level to $val. 0=off 3=noisy. $val default is 0. returns no value. When the value is greater than 1, the \*(C`HTTP::DAV::Comms\*(C' module will log all of the client<=>server interactions into /tmp/perldav_debug.txt.

\s-1DAV\s0 \s-1OPERATIONS\s0

For all of the following operations, \s-1URL\s0 can be absolute (http://host.org/dav/) or relative (../dir2/). The only operation that requires an absolute \s-1URL\s0 is open.

copy(\s-1URL\s0,DEST,[\s-1OVERWRITE\s0],[\s-1DEPTH\s0])

copies one remote resource to another

is the remote resource you'd like to copy. Mandatory is the remote target for the copy command. Mandatory optionally indicates whether the server should fail if the target exists. Valid values are \*(L"T\*(R" and \*(L"F\*(R" (1 and 0 are synonymous). Default is T. optionally indicates whether the server should do a recursive copy or not. Valid values are 0 and (1 or \*(L"infinity\*(R"). Default is \*(L"infinity\*(R" (1).

The return value is always 1 or 0 indicating success or failure. Requires a working resource to be set before being called. See \*(C`open\*(C'. Note: if either 'URL' or 'DEST' are locked by this dav client, then the lock headers will be taken care of automatically. If the either of the two \s-1URL\s0's are locked by someone else, the server should reject the request. copy examples: $d->open(-url=>"host.org/dav_dir/"); Recursively copy dir1/ to dir2/ $d->copy(-url=>"dir1/", -dest=>"dir2/"); Non-recursively and non-forcefully copy dir1/ to dir2/ $d->copy(-url=>"dir1/", -dest=>"dir2/",-overwrite=>0,-depth=>0); Create a copy of dir1/file.txt as dir2/file.txt $d->cwd(-url=>"dir1/"); $d->copy("file.txt","../dir2"); Create a copy of file.txt as dir2/new_file.txt $d->copy("file.txt","/dav_dir/dir2/new_file.txt")

cwd(\s-1URL\s0)

changes the remote working directory. This is synonymous to open except that the \s-1URL\s0 can be relative and may contain a \*(C`glob\*(C' (the first match in a glob will be used). $d->open("host.org/dav_dir/dir1/"); $d->cwd("../dir2"); $d->cwd(-url=>"../dir1"); The return value is always 1 or 0 indicating success or failure. Requires a working resource to be set before being called. See \*(C`open\*(C'. You can not cwd to files, only collections (directories).

delete(\s-1URL\s0)

deletes a remote resource. $d->open("host.org/dav_dir/"); $d->delete("index.html"); $d->delete("./dir1"); $d->delete(-url=>"/dav_dir/dir2/file*",-callback=>\&mycallback); is the remote resource(s) you'd like to delete. It can be a file, directory or \*(C`glob\*(C'. The return value is always 1 or 0 indicating success or failure. Requires a working resource to be set before being called. See \*(C`open\*(C'. This command will recursively delete directories. \s-1BE\s0 \s-1CAREFUL\s0 of uninitialised file variables in situation like this: $d->delete(\*(L"$dir/$file\*(R"). This will trash your $dir if $file is not set.

get(\s-1URL\s0,[\s-1TO\s0],[\s-1CALLBACK\s0])

downloads the file or directory at \*(C`URL\*(C' to the local location indicated by \*(C`TO\*(C'.

is the remote resource you'd like to get. It can be a file or directory or a \*(L"glob\*(R". is where you'd like to put the remote resource. The -to parameter can be: - a B<filename> indicating where to save the contents.

- a B<FileHandle reference>.

- a reference to a B<scalar object> into which the contents will be saved. If the \*(C`-url\*(C' matches multiple files (via a glob or a directory download), then the \*(C`get\*(C' routine will return an error if you try to use a FileHandle reference or a scalar reference. is a reference to a callback function which will be called everytime a file is completed downloading. The idea of the callback function is that some recursive get's can take a very long time and the user may require some visual feedback. See \s-1CALLBACKS\s0 for an examples and how to use a callback.

The return value of get is always 1 or 0 indicating whether the entire get sequence was a success or if there was \s-1ANY\s0 failures. For instance, in a recursive get, if the server couldn't open 1 of the 10 remote files, for whatever reason, then the return value will be 0. This is so that you can have your script call the \*(C`errors()\*(C' routine to handle error conditions. Previous versions of \s-1HTTP::DAV\s0 allowed the return value to be the file contents if no -to attribute was supplied. This functionality is deprecated. Requires a working resource to be set before being called. See \*(C`open\*(C'. get examples: $d->open("host.org/dav_dir/"); Recursively get remote my_dir/ to . $d->get("my_dir/","."); Recursively get remote my_dir/ to /tmp/my_dir/ calling &mycallback($success,$mesg) everytime a file operation is completed. $d->get("my_dir","/tmp",\&mycallback); Get remote my_dir/index.html to /tmp/index.html $d->get(-url=>"/dav_dir/my_dir/index.html",-to=>"/tmp"); Get remote index.html to /tmp/index1.html $d->get("index.html","/tmp/index1.html"); Get remote index.html to a filehandle my $fh = new FileHandle; $fh->open(">/tmp/index1.html"); $d->get("index.html",\$fh); Get remote index.html as a scalar (into the string $file_contents): my $file_contents; $d->get("index.html",\$file_contents); Get all of the files matching the globs file1* and file2*: $d->get("file[12]*","/tmp"); Get all of the files matching the glob file?.html: $d->get("file?.html","/tmp"); # downloads file1.html and file2.html but not file3.html or file1.txt Invalid glob: $d->get("/dav_dir/*/index.html","/tmp"); # Can not glob like this.

lock([\s-1URL\s0],[\s-1OWNER\s0],[\s-1DEPTH\s0],[\s-1TIMEOUT\s0],[\s-1SCOPE\s0],[\s-1TYPE\s0])

locks a resource. If \s-1URL\s0 is not specified, it will lock the current working resource (opened resource). $d->lock( -url => "index.html", -owner => "Patrick Collins", -depth => "infinity", -scope => "exclusive", -type => "write", -timeout => "10h" ) See \*(C`HTTP::DAV::Resource\*(C' lock() for details of the above parameters. The return value is always 1 or 0 indicating success or failure. Requires a working resource to be set before being called. See \*(C`open\*(C'. When you lock a resource, the lock is held against the current \s-1HTTP::DAV\s0 object. In fact, the locks are held in a \*(C`HTTP::DAV::ResourceList\*(C' object. You can operate against all of the locks that you have created as follows: ## Print and unlock all locks that we own. my $rl_obj = $d->get_lockedresourcelist(); foreach $resource ( $rl_obj->get_resources() ) { @locks = $resource->get_locks(-owned=>1); foreach $lock ( @locks ) { print $resource->get_uri . "\n"; print $lock->as_string . "\n"; } ## Unlock them? $resource->unlock; } Typically, a simple $d->unlock($uri) will suffice. lock example $d->lock($uri, -timeout=>"1d"); ... $d->put("/tmp/index.html",$uri); $d->unlock($uri);

mkcol(\s-1URL\s0)

make a remote collection (directory) The return value is always 1 or 0 indicating success or failure. Requires a working resource to be set before being called. See \*(C`open\*(C'. $d->open("host.org/dav_dir/"); $d->mkcol("new_dir"); # Should succeed $d->mkcol("/dav_dir/new_dir"); # Should succeed $d->mkcol("/dav_dir/new_dir/xxx/yyy"); # Should fail

move(\s-1URL\s0,DEST,[\s-1OVERWRITE\s0],[\s-1DEPTH\s0])

moves one remote resource to another

is the remote resource you'd like to move. Mandatory is the remote target for the move command. Mandatory optionally indicates whether the server should fail if the target exists. Valid values are \*(L"T\*(R" and \*(L"F\*(R" (1 and 0 are synonymous). Default is T.

Requires a working resource to be set before being called. See \*(C`open\*(C'. The return value is always 1 or 0 indicating success or failure. Note: if either 'URL' or 'DEST' are locked by this dav client, then the lock headers will be taken care of automatically. If either of the two \s-1URL\s0's are locked by someone else, the server should reject the request. move examples: $d->open(-url=>"host.org/dav_dir/"); move dir1/ to dir2/ $d->move(-url=>"dir1/", -dest=>"dir2/"); non-forcefully move dir1/ to dir2/ $d->move(-url=>"dir1/", -dest=>"dir2/",-overwrite=>0); Move dir1/file.txt to dir2/file.txt $d->cwd(-url=>"dir1/"); $d->move("file.txt","../dir2"); move file.txt to dir2/new_file.txt $d->move("file.txt","/dav_dir/dir2/new_file.txt")

open(\s-1URL\s0)

opens the directory (collection resource) at \s-1URL\s0. open will perform a propfind against \s-1URL\s0. If the server does not understand the request then the open will fail. Similarly, if the server indicates that the resource at \s-1URL\s0 is \s-1NOT\s0 a collection, the open command will fail.

options([\s-1URL\s0])

Performs an \s-1OPTIONS\s0 request against the \s-1URL\s0 or the working resource if \s-1URL\s0 is not supplied. Requires a working resource to be set before being called. See \*(C`open\*(C'. The return value is a string of comma separated \s-1OPTIONS\s0 that the server states are legal for \s-1URL\s0 or undef otherwise. A fully compliant \s-1DAV\s0 server may offer as many methods as: \s-1OPTIONS\s0, \s-1TRACE\s0, \s-1GET\s0, \s-1HEAD\s0, \s-1DELETE\s0, \s-1PUT\s0, \s-1COPY\s0, \s-1MOVE\s0, \s-1PROPFIND\s0, \s-1PROPPATCH\s0, \s-1LOCK\s0, \s-1UNLOCK\s0 Note: \s-1IIS5\s0 does not support \s-1PROPPATCH\s0 or \s-1LOCK\s0 on collections. Example: $options = $d->options($url); print $options . "\n"; if ($options=~ /\bPROPPATCH\b/) { print "OK to proppatch\n"; } Or, put more simply: if ( $d->options($url) =~ /\bPROPPATCH\b/ ) { print "OK to proppatch\n"; }

propfind([\s-1URL\s0],[\s-1DEPTH\s0])

Perform a propfind against \s-1URL\s0 at \s-1DEPTH\s0 depth. \*(C`-depth\*(C' can be used to specify how deep the propfind goes. \*(L"0\*(R" is collection only. \*(L"1\*(R" is collection and it's immediate members (This is the default value). \*(L"infinity\*(R" is the entire directory tree. Note that most \s-1DAV\s0 compliant servers deny \*(L"infinity\*(R" depth propfinds for security reasons. Requires a working resource to be set before being called. See \*(C`open\*(C'. The return value is an \*(C`HTTP::DAV::Resource\*(C' object on success or 0 on failure. The Resource object can be used for interrogating properties or performing other operations. ## Print collection or content length if ( $r=$d->propfind( -url=>"/my_dir", -depth=>1) ) { if ( $r->is_collection ) { print "Collection\n" print $r->get_resourcelist->as_string . "\n" } else { print $r->get_property("getcontentlength") ."\n"; } } Please note that although you may set a different namespace for a property of a resource during a set_prop, \s-1HTTP::DAV\s0 currently ignores all \s-1XML\s0 namespaces so you will get clashes if two properties have the same name but in different namespaces. Currently this is unavoidable but I'm working on the solution.

proppatch([\s-1URL\s0],[\s-1NAMESPACE\s0],PROPNAME,PROPVALUE,ACTION,[\s-1NSABBR\s0])

If \*(C`-action\*(C' equals \*(L"set\*(R" then we set a property named \*(C`-propname\*(C' to \*(C`-propvalue\*(C' in the namespace \*(C`-namespace\*(C' for \*(C`-url\*(C'. If \*(C`-action\*(C' equals \*(L"remove\*(R" then we unset a property named \*(C`-propname\*(C' in the namespace \*(C`-namespace\*(C' for \*(C`-url\*(C'. If no action is supplied then the default action is \*(L"set\*(R". The return value is an \*(C`HTTP::DAV::Resource\*(C' object on success or 0 on failure. The Resource object can be used for interrogating properties or performing other operations. To explicitly set a namespace in which to set the propname then you can use the \*(C`-namespace\*(C' and \*(C`-nsabbr\*(C' (namespace abbreviation) parameters. But you're welcome to play around with \s-1DAV\s0 namespaces. Requires a working resource to be set before being called. See \*(C`open\*(C'. It is recommended that you use \*(C`set_prop\*(C' and \*(C`unset_prop\*(C' instead of proppatch for readability. \*(C`set_prop\*(C' simply calls \*(C`proppatch(-action=\*(C'set)> and \*(C`unset_prop\*(C' calls \*(C`proppatch(-action=\*(C'\*(L"remove\*(R")> See \*(C`set_prop\*(C' and \*(C`unset_prop\*(C' for examples.

put(\s-1LOCAL\s0,[\s-1URL\s0],[\s-1CALLBACK\s0],[\s-1HEADERS\s0])

uploads the files or directories at \*(C`-local\*(C' to the remote destination at \*(C`-url\*(C'. \*(C`-local\*(C' points to a file, directory or series of files or directories (indicated by a glob). If the filename contains any of the characters `*', `?' or `[' it is a candidate for filename substitution, also known as ``globbing''. This word is then regarded as a pattern (``glob-pattern''), and replaced with an alphabetically sorted list of file names which match the pattern. One can upload/put a string by passing a reference to a scalar in the -local parameter. See example below. put requires a working resource to be set before being called. See \*(C`open\*(C'. The return value is always 1 or 0 indicating success or failure. See get() for a description of what the optional callback parameter does. You can also pass a \*(C`-headers\*(C' argument. That allows to specify custom \s-1HTTP\s0 headers. It can be either a hashref with header names and values, or a HTTP::Headers object. put examples: Put a string to the server: my $myfile = "This is the contents of a file to be uploaded\n"; $d->put(-local=>\$myfile,-url=>"http://www.host.org/dav_dir/file.txt"); Put a local file to the server: $d->put(-local=>"/tmp/index.html",-url=>"http://www.host.org/dav_dir/"); Put a series of local files to the server: In these examples, /tmp contains file1.html, file1, file2.html, file2.txt, file3.html, file2/

$d->put(-local=>"/tmp/file[12]*",-url=>"http://www.host.org/dav_dir/");

uploads file1.html, file1, file2.html, file2.txt and the directory file2/ to dav_dir/.

set_prop([\s-1URL\s0],[\s-1NAMESPACE\s0],PROPNAME,PROPVALUE)

Sets a property named \*(C`-propname\*(C' to \*(C`-propvalue\*(C' in the namespace \*(C`-namespace\*(C' for \*(C`-url\*(C'. Requires a working resource to be set before being called. See \*(C`open\*(C'. The return value is an \*(C`HTTP::DAV::Resource\*(C' object on success or 0 on failure. The Resource object can be used for interrogating properties or performing other operations. Example: if ( $r = $d->set_prop(-url=>$url, -namespace=>"dave", -propname=>"author", -propvalue=>"Patrick Collins" ) ) { print "Author property set\n"; } else { print "set_prop failed:" . $d->message . "\n"; } See the note in propfind about namespace support in \s-1HTTP::DAV\s0. They're settable, but not readable.

steal([\s-1URL\s0])

forcefully steals any locks held against \s-1URL\s0. steal will perform a propfind against \s-1URL\s0 and then, any locks that are found will be unlocked one by one regardless of whether we own them or not. Requires a working resource to be set before being called. See \*(C`open\*(C'. The return value is always 1 or 0 indicating success or failure. If multiple locks are found and unlocking one of them fails then the operation will be aborted. if ($d->steal()) { print "Steal succeeded\n"; } else { print "Steal failed: ". $d->message() . "\n"; }

unlock([\s-1URL\s0])

unlocks any of our locks on \s-1URL\s0. Requires a working resource to be set before being called. See \*(C`open\*(C'. The return value is always 1 or 0 indicating success or failure. if ($d->unlock()) { print "Unlock succeeded\n"; } else { print "Unlock failed: ". $d->message() . "\n"; }

unset_prop([\s-1URL\s0],[\s-1NAMESPACE\s0],PROPNAME)

Unsets a property named \*(C`-propname\*(C' in the namespace \*(C`-namespace\*(C' for \*(C`-url\*(C'. Requires a working resource to be set before being called. See \*(C`open\*(C'. The return value is an \*(C`HTTP::DAV::Resource\*(C' object on success or 0 on failure. The Resource object can be used for interrogating properties or performing other operations. Example: if ( $r = $d->unset_prop(-url=>$url, -namespace=>"dave", -propname=>"author", ) ) { print "Author property was unset\n"; } else { print "set_prop failed:" . $d->message . "\n"; } See the note in propfind about namespace support in \s-1HTTP::DAV\s0. They're settable, but not readable.

\s-1ACCESSOR\s0 \s-1METHODS\s0

get_user_agent

Returns the clients' working \*(C`HTTP::DAV::UserAgent\*(C' object. You may want to interact with the \*(C`HTTP::DAV::UserAgent\*(C' object to modify request headers or provide advanced authentication procedures. See dave for an advanced authentication procedure.

get_last_request

Takes no arguments and returns the clients' last outgoing \*(C`HTTP::Request\*(C' object. You would only use this to inspect a request that has already occurred. If you would like to modify the \*(C`HTTP::Request\*(C' \s-1BEFORE\s0 the \s-1HTTP\s0 request takes place (for instance to add another header), you will need to get the \*(C`HTTP::DAV::UserAgent\*(C' using \*(C`get_user_agent\*(C' and interact with that.

get_workingresource

Returns the currently \*(L"opened\*(R" or \*(L"working\*(R" resource (\*(C`HTTP::DAV::Resource\*(C'). The working resource is changed whenever you open a url or use the cwd command. e.g.

  $r = $d->get_workingresource
  print \*(L"pwd: \*(R" . $r->get_uri . \*(L"\n\*(R";
get_workingurl

Returns the currently \*(L"opened\*(R" or \*(L"working\*(R" \*(C`URL\*(C'. The working resource is changed whenever you open a url or use the cwd command. print "pwd: " . $d->get_workingurl . "\n";

get_lockedresourcelist

Returns an \*(C`HTTP::DAV::ResourceList\*(C' object that represents all of the locks we've created using \s-1THIS\s0 dav client. print "pwd: " . $d->get_workingurl . "\n";

get_absolute_uri(\s-1REL_URI\s0,[\s-1BASE_URI\s0])

This is a useful utility function which joins \*(C`BASE_URI\*(C' and \*(C`REL_URI\*(C' and returns a new \s-1URI\s0. If \*(C`BASE_URI\*(C' is not supplied then the current working resource (as indicated by get_workingurl) is used. If \*(C`BASE_URI\*(C' is not set and there is no current working resource the \*(C`REL_URI\*(C' will be returned. For instance: $d->open(\*(L"http://host.org/webdav/dir1/\*(R"); # Returns "http://host.org/webdav/dir2/" $d->get_absolute_uri(-rel_uri=>"../dir2");

# Returns "http://x.org/dav/dir2/file.txt" $d->get_absolute_uri(-rel_uri =>"dir2/file.txt", ->base_uri=>"http://x.org/dav/"); Note that it subtly takes care of trailing slashes.

\s-1ERROR\s0 \s-1HANDLING\s0 \s-1METHODS\s0

message

\*(C`message\*(C' gets the last success or error message. The return value is always a scalar (string) and will change everytime a dav operation is invoked (lock, cwd, put, etc). See also \*(C`errors\*(C' for operations which contain multiple error messages.

errors

Returns an @array of error messages that had been set during a multi-request operation. Some of \*(C`HTTP::DAV\*(C''s operations perform multiple request to the server. At the time of writing only put and get are considered multi-request since they can operate recursively requiring many \s-1HTTP\s0 requests. In these situations you should check the errors array if to determine if any of the requests failed. The \*(C`errors\*(C' function is used for multi-request operations and not to be confused with a multi-status server response. A multi-status server response is when the server responds with multiple error messages for a \s-1SINGLE\s0 request. To deal with multi-status responses, see \*(C`HTTP::DAV::Response\*(C'. # Recursive put if (!$d->put( "/tmp/my_dir", $url ) ) { # Get the overall message print $d->message; # Get the individual messages foreach $err ( $d->errors ) { print " Error:$err\n" } }

is_success

Returns the status of the last \s-1DAV\s0 operation performed through the \s-1HTTP::DAV\s0 interface. This value will always be the same as the value returned from an HTTP::DAV::method. For instance: # This will always evaluate to true ($d->lock($url) eq $d->is_success) ? You may want to use the is_success method if you didn't capture the return value immediately. But in most circumstances you're better off just evaluating as follows:

  if($d->lock($url)) { ... }
get_last_response

Takes no arguments and returns the last seen \*(C`HTTP::DAV::Response\*(C' object. You may want to use this if you have just called a propfind and need the individual error messages returned in a MultiStatus. If you find that you're using get_last_response() method a lot, you may be better off using the more advanced \*(C`HTTP::DAV\*(C' interface and interacting with the HTTP::DAV::* interfaces directly as discussed in the intro. For instance, if you find that you're always wanting a detailed understanding of the server's response headers or messages, then you're probably better off using the \*(C`HTTP::DAV::Resource\*(C' methods and interpreting the \*(C`HTTP::DAV::Response\*(C' directly. To perform detailed analysis of the server's response (if for instance you got back a multistatus response) you can call \*(C`get_last_response()\*(C' which will return to you the most recent response object (always the result of the last operation, \s-1PUT\s0, \s-1PROPFIND\s0, etc). With the returned HTTP::DAV::Response object you can handle multi-status responses. For example: # Print all of the messages in a multistatus response if (! $d->unlock($url) ) { $response = $d->get_last_response(); if ($response->is_multistatus() ) { foreach $num ( 0 .. $response->response_count() ) { ($err_code,$mesg,$url,$desc) = $response->response_bynum($num); print "$mesg ($err_code) for $url\n"; } } }

\s-1ADVANCED\s0 \s-1METHODS\s0

new_resource

Creates a new resource object with which to play. This is the preferred way of creating an \*(C`HTTP::DAV::Resource\*(C' object if required. Why? Because each Resource object needs to sit within a global \s-1HTTP::DAV\s0 client. Also, because the new_resource routine checks the \*(C`HTTP::DAV\*(C' locked resource list before creating a new object. $dav->new_resource( -uri => "http://..." );

set_workingresource(\s-1URL\s0)

Sets the current working resource to \s-1URL\s0. You shouldn't need this method. Call open or cwd to set the working resource. You \s-1CAN\s0 call \*(C`set_workingresource()\*(C' but you will need to perform a \*(C`propfind\*(C' immediately following it to ensure that the working resource is valid.

INSTALLATION, TODO, MAILING LISTS and REVISION HISTORY

[\s-1OUTDATED\s0]

Please see the primary \s-1HTTP::DAV\s0 webpage at (http://www.webdav.org/perldav/http-dav/) or the \s-1README\s0 file in this library.

RELATED TO HTTP::DAV…

You'll want to also read:

and maybe if you're more inquisitive:

AUTHOR AND COPYRIGHT

This module is Copyright (C) 2001-2008 by

Patrick Collins G03 Gloucester Place, Kensington Sydney, Australia

Email: [email protected] Phone: +61 2 9663 4916

All rights reserved.

Current co-maintainer of the module is Cosimo Streppone for Opera Software \s-1ASA\s0, [email protected].

You may distribute this module under the terms of either the \s-1GNU\s0 General Public License or the Artistic License, as specified in the Perl \s-1README\s0 file.

POD ERRORS

Hey! The above document had some coding errors, which are explained below:

Around line 2030:

=over should be: '=over' or '=over positive_number'

Around line 2042:

=over should be: '=over' or '=over positive_number'