Skip to content

Instantly share code, notes, and snippets.

@drmalex07
Last active November 22, 2023 16:58
Show Gist options
  • Save drmalex07/a179c0ba4ee95a807b04f07a8e5b03f9 to your computer and use it in GitHub Desktop.
Save drmalex07/a179c0ba4ee95a807b04f07a8e5b03f9 to your computer and use it in GitHub Desktop.
List directory in WebDav #webdav

Readme - List directory in WebDAV

1. An example request

To list properties of a directory we must use the PROPFIND method of WebDAV protocol and provide a request body with properties we are interested into. We must also provide the Depth header (otherwise the request is rejected as 403 Forbidden).

To retrieve basic properties as size and type, prepare a request body (say propfind-basic.xml) as:

<propfind xmlns="DAV:">
  <prop>
    <getlastmodified xmlns="DAV:"/>
    <getcontentlength xmlns="DAV:"/>
    <executable xmlns="http://apache.org/dav/props/"/>
    <resourcetype xmlns="DAV:"/>
  </prop>
</propfind>

To find all available properties (without their values), prepare a request body (say propfind-available.xml) as:

<?xml version="1.0" encoding="utf-8" ?>
<propfind xmlns="DAV:">
   <propname/>
</propfind>

Perform the request:

curl -v -X PROPFIND \
    -H "Content-Type: application/xml" -H "Accept: application/xml" \
    -H "Depth: 1" \
    -d @propfind.xml http://webdav.internal/

2. An example server configuration

An example configuration for Apache2's mod_dav module:

Alias "/files" "/var/www/html"
<Location "/files">
    DAV on
    AllowOverride none
	    
    Options +Indexes
    DirectoryIndex disabled
        
    AuthType Basic
    AuthName "WebDAV Area"
    AuthDigestProvider file
    AuthUserFile "/etc/apache2/passwd"
    Require user "admin" 
</Location>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment