Skip to content
Jennifer Programming Language

webdav API reference

A WebDAV client (RFC 4918): list, stat, read, write, create, move, copy and delete files on any WebDAV server (Nextcloud, ownCloud, Apache mod_dav, nginx, rclone, a NAS), plus propfind / proppatch for any property.

The module has two layers. The protocol layer (Resource, paths and hrefs, the multistatus codec, Clark notation for property names) knows nothing about sockets, so a server built on httpd can share it: it encodes the same Resource the client decodes. The client sends the requests over http and keeps the session in a value-semantic Client. Needs the default jennifer binary (net via http).

Every failure throws a webdav.WebdavError (kind "webdav") with the request's method, path and refused status (412 for a failed ifMatch, 423 locked, ...); for a 207 Multi-Status reply, the first failed member. The generic kinds go on: a socket failure is http's net.NetError (kind "net"), a reached cap kind "limit", a server that stops answering "timeout" and a reply cut short "closed".

A credential (an Authorization or Cookie header) goes only over https://, or http:// to a loopback host; any other http:// URL throws before the request is sent, unless the client sets allowInsecureHttp.

Import with import "webdav.j" as webdav;. See the webdav guide for prose and examples.

Contents

NameWhat it is
clarkA property name in Clark notation, as Resource.props, propfind and proppatch take it.
cleanPathA path checked and normalized: a leading /, no empty, . or .. segment, no control character, no trail...
connectA client for a WebDAV server below a URL, with no credential yet.
copyCopy a file, or a collection with everything in it.
decodeHrefThe decoded server path of an href, which a server may send as a path or as a full URL.
deleteDelete a file, or a collection with everything in it.
encodeHrefA decoded path as an href: each segment percent-encoded.
existsWhether a path exists.
getRead a file.
mkdirCreate a collection.
mkdirAllCreate a collection and any missing parents.
moveMove or rename a file or collection.
multistatusEncode resources as a 207 Multi-Status body: what a server answers a PROPFIND, and the inverse of...
parseMultistatusDecode a 207 Multi-Status body into its resources.
propfindAsk for properties of a path, and of its members with depth 1.
proppatchSet or remove properties of a path, all or none.
putWrite a file, replacing it when it exists.
putWithWrite a file with a media type or a condition.
readDirThe members of a collection, without the collection itself.
statOne file or collection.
walkEverything below a collection, collections before their members.
withBasicAuthAuthenticate with a user name and password (HTTP Basic).
withCATrust a certificate (PEM) instead of the system roots.
withHeaderSend a header with every request, such as OCS-APIRequest: true.
withSkipVerifyAccept any certificate.
withTimeoutSet the idle timeout of each request.
withTokenAuthenticate with a bearer token.
Clientstruct: A connection to a WebDAV server below a base URL.
PutOptionsstruct: How putWith writes a file.
Resourcestruct: A file or collection and its properties, as a PROPFIND reports it (and as a server answers one).
WebdavErrorstruct: A failed WebDAV operation.
constantsthe module's constants

Functions

clark

jennifer
webdav.clark(ns as string, local as string)

A property name in Clark notation, as Resource.props, propfind and proppatch take it.

ns
the namespace URI, e.g. DAV:
local
the local name, e.g. getetag
Returns string
e.g. {DAV:}getetag

cleanPath

jennifer
webdav.cleanPath(path as string)

A path checked and normalized: a leading /, no empty, . or .. segment, no control character, no trailing /.

path
e.g. /Documents/a.txt; "" or / for the root
Returns string
the path; / for the root

connect

jennifer
webdav.connect(url as string)

A client for a WebDAV server below a URL, with no credential yet.

url
http:// or https://, e.g. https://cloud.example.com/remote.php/dav/files/alice
Returns Client
the client; 30 s idle timeout, full certificate checking
Throws WebdavError
kind "webdav" on a URL that is not http(s) or carries credentials (use withBasicAuth), a query or a fragment

copy

jennifer
webdav.copy(
    c as Client,
    source as string,
    target as string,
    overwrite as bool)

Copy a file, or a collection with everything in it.

c
the client
source
e.g. /Templates/report.odt
target
e.g. /Documents/report.odt
overwrite
replace an existing destination
Throws WebdavError
kind "webdav" as move

decodeHref

jennifer
webdav.decodeHref(href as string)

The decoded server path of an href, which a server may send as a path or as a full URL.

href
e.g. /a%20b/ or https://host/a%20b/
Returns string
the decoded path, e.g. /a b/

delete

jennifer
webdav.delete(c as Client, path as string)

Delete a file, or a collection with everything in it.

c
the client
path
e.g. /Documents/old
Throws WebdavError
kind "webdav" on the root, when it does not exist (HTTP 404), or when the server cannot delete all of it (HTTP 207, naming the first member it kept)

encodeHref

jennifer
webdav.encodeHref(path as string, isDir as bool)

A decoded path as an href: each segment percent-encoded.

path
a clean path
isDir
add the trailing / of a collection
Returns string
the href, e.g. /My%20Files/

exists

jennifer
webdav.exists(c as Client, path as string)

Whether a path exists.

c
the client
path
e.g. /Documents/a.txt
Returns bool
whether it does
Throws WebdavError
kind "webdav" on a bad path or any answer but 207 and 404

get

jennifer
webdav.get(c as Client, path as string, maxBytes as int)

Read a file.

c
the client
path
e.g. /Documents/a.txt
maxBytes
the largest file accepted; 0 for 64 MiB, math.MAX_INT for no limit
Returns bytes
its content
Throws WebdavError
kind "webdav" when it does not exist or the server refuses, or for a negative maxBytes
Throws Error
kind "limit" when it is larger than maxBytes

mkdir

jennifer
webdav.mkdir(c as Client, path as string)

Create a collection. Its parent must exist.

c
the client
path
e.g. /Documents/2026
Throws WebdavError
kind "webdav" when it exists (HTTP 405), the parent does not (HTTP 409), or the server refuses

mkdirAll

jennifer
webdav.mkdirAll(c as Client, path as string)

Create a collection and any missing parents. An existing one is no error.

c
the client
path
e.g. /Backups/2026/11
Throws WebdavError
kind "webdav" when a part of the path is a file, or the server refuses

move

jennifer
webdav.move(
    c as Client,
    source as string,
    target as string,
    overwrite as bool)

Move or rename a file or collection.

c
the client
source
e.g. /Inbox/scan.pdf
target
e.g. /Documents/scan.pdf
overwrite
replace an existing destination
Throws WebdavError
kind "webdav" when the destination exists and overwrite is false (HTTP 412), its parent does not (HTTP 409), or the server refuses

multistatus

jennifer
webdav.multistatus(resources as list of Resource)

Encode resources as a 207 Multi-Status body: what a server answers a PROPFIND, and the inverse of parseMultistatus.

resources
the resources; href is their server path, decoded; each entry of props is written as text
Returns string
the XML, with its declaration

parseMultistatus

jennifer
webdav.parseMultistatus(body as string)

Decode a 207 Multi-Status body into its resources. Properties a server reports with a non-2xx status are left out, and so are responses that are a status only (404 for a member that vanished).

body
the XML
Returns list of Resource
the resources, in the order of the reply; path is "" (the client fills it in)
Throws WebdavError
kind "webdav" when the body is not a DAV:multistatus, a response has no DAV:href or neither a DAV:propstat nor a DAV:status, a status line is malformed, or a size, quota or date is not one
Throws Error
kind "limit" for a body past xml's decoding caps

propfind

jennifer
webdav.propfind(
    c as Client,
    path as string,
    depth as int,
    props as list of string)

Ask for properties of a path, and of its members with depth 1.

c
the client
path
e.g. /Documents
depth
0 for the path, 1 for it and its members
props
Clark names, e.g. {http://owncloud.org/ns}fileid; [] for all the server offers
Returns list of Resource
the path first, then its members
Throws WebdavError
kind "webdav" on a bad path, depth or name, or when the server refuses

proppatch

jennifer
webdav.proppatch(
    c as Client,
    path as string,
    set as map of string to string,
    remove as list of string)

Set or remove properties of a path, all or none.

c
the client
path
e.g. /Documents/a.txt
set
text properties to set, by Clark name, e.g. {http://owncloud.org/ns}favorite: "1"
remove
properties to remove, by Clark name
Throws WebdavError
kind "webdav" on a bad name, or when the server refuses a property (naming it)

put

jennifer
webdav.put(c as Client, path as string, data as bytes)

Write a file, replacing it when it exists.

c
the client
path
e.g. /Documents/a.txt; its collection must exist
data
the content
Returns string
the new entity tag when the server sends one; "" otherwise
Throws WebdavError
kind "webdav" when the collection does not exist (HTTP 409), or the server refuses

putWith

jennifer
webdav.putWith(
    c as Client,
    path as string,
    data as bytes,
    options as PutOptions)

Write a file with a media type or a condition.

c
the client
path
e.g. /Documents/a.txt
data
the content
options
the media type, and ifMatch / onlyIfNew
Returns string
the new entity tag when the server sends one; "" otherwise
Throws WebdavError
kind "webdav" when a condition fails (HTTP 412), on a weak ifMatch tag, or as put

readDir

jennifer
webdav.readDir(c as Client, path as string)

The members of a collection, without the collection itself.

c
the client
path
e.g. /Documents; / for the client's URL
Returns list of Resource
the members, in the server's order
Throws WebdavError
kind "webdav" when it is a file, does not exist, the server lists a path that is not a direct member, or the server refuses

stat

jennifer
webdav.stat(c as Client, path as string)

One file or collection.

c
the client
path
e.g. /Documents/a.txt
Returns Resource
it
Throws WebdavError
kind "webdav" when it does not exist (HTTP 404), or when the server refuses

walk

jennifer
webdav.walk(c as Client, path as string)

Everything below a collection, collections before their members. It asks with depth 1 per collection, since many servers refuse Depth: infinity.

c
the client
path
the collection
Returns list of Resource
the files and collections below it
Throws Error
kind "limit" past MAX_WALK entries
Throws WebdavError
kind "webdav" as readDir

withBasicAuth

jennifer
webdav.withBasicAuth(c as Client, user as string, password as string)

Authenticate with a user name and password (HTTP Basic). They travel readable, so a request over http:// to a host other than loopback throws unless the client sets allowInsecureHttp.

c
the client
user
the user name, without :
password
the password; an app password where the server offers them
Returns Client
the changed copy
Throws WebdavError
kind "webdav" on a : in the name or a control character

withCA

jennifer
webdav.withCA(c as Client, pem as bytes)

Trust a certificate (PEM) instead of the system roots.

c
the client
pem
the certificate
Returns Client
the changed copy

withHeader

jennifer
webdav.withHeader(c as Client, name as string, value as string)

Send a header with every request, such as OCS-APIRequest: true.

c
the client
name
the header name
value
its value
Returns Client
the changed copy
Throws WebdavError
kind "webdav" on a bad name, a value with a line break, or a header that frames the request (Host, Content-Length, ...)

withSkipVerify

jennifer
webdav.withSkipVerify(c as Client)

Accept any certificate. The connection stays encrypted but is no longer authenticated; prefer withCA.

c
the client
Returns Client
the changed copy

withTimeout

jennifer
webdav.withTimeout(c as Client, ms as int)

Set the idle timeout of each request.

c
the client
ms
milliseconds; 0 for the default, 30 s
Returns Client
the changed copy

withToken

jennifer
webdav.withToken(c as Client, token as string)

Authenticate with a bearer token.

c
the client
token
the token
Returns Client
the changed copy
Throws WebdavError
kind "webdav" on a space or control character in it

Structs

Client

A connection to a WebDAV server below a base URL. Value-semantic: the with* functions return a changed copy.

jennifer
def struct Client {
    url as string,
    basePath as string,
    headers as map of string to string,
    tls as http.TlsOptions,
    timeoutMs as int,
    allowInsecureHttp as bool
};
url
the base URL without a trailing slash, e.g. https://cloud.example.com/remote.php/dav/files/alice
basePath
its path, percent-decoded; "" for the server root
headers
sent with every request (the credential among them)
tls
certificate checking
timeoutMs
the idle timeout of each request
allowInsecureHttp
send a credential over plain http:// to a non-loopback host (default false: such a request throws before it is sent)

PutOptions

How putWith writes a file.

jennifer
def struct PutOptions {
    contentType as string,
    ifMatch as string,
    onlyIfNew as bool
};
contentType
the media type; "" for application/octet-stream
ifMatch
an entity tag the file must still have (from Resource.etag), so a change made meanwhile is not overwritten; "" for none. It must be strong: a weak W/"..." tag can never match
onlyIfNew
refuse to replace an existing file

Resource

A file or collection and its properties, as a PROPFIND reports it (and as a server answers one).

jennifer
def struct Resource {
    href as string,
    path as string,
    name as string,
    isDir as bool,
    size as int,
    modified as int,
    etag as string,
    contentType as string,
    quotaUsed as int,
    quotaAvailable as int,
    props as map of string to string
};
href
the server path, percent-decoded, e.g. /remote.php/dav/files/alice/a.txt; a collection's ends in /
path
the path below the client's URL, e.g. /a.txt; "/" for the URL itself
name
the last segment; "" for the server root
isDir
whether it is a collection
size
bytes (getcontentlength); 0 for a collection
modified
last change, Unix seconds (getlastmodified); 0 when unknown
etag
the entity tag as sent, quotes included, for ifMatch
contentType
the media type; "" when unknown
quotaUsed
bytes used (RFC 4331); -1 when not reported
quotaAvailable
bytes available (RFC 4331); -1 when not reported
props
every other property by its Clark name ({http://owncloud.org/ns}fileid): its text, or its XML when it holds elements

WebdavError

A failed WebDAV operation. Every error of kind "webdav" is one, so its fields are safe to read once the kind matches.

jennifer
def struct WebdavError {
    kind as string,
    message as string,
    method as string,
    path as string,
    status as int,
    member as string
};
kind
always "webdav" (ERROR_KIND)
message
webdav: <method> <path>: and what went wrong
method
the request's method (GET, PUT, MOVE, ...); "" for a local check
path
the request's path; "" for a local check
status
the refused status: the response's (404, 409, 412 a failed ifMatch, 423 locked, 507), or for a 207 Multi-Status the first failed member's; 0 when no response was read
member
for a 207 Multi-Status, the path of the first member the server reports as failed; "" otherwise

Constants

webdav.DAV_NS as string
The DAV: namespace of the WebDAV properties and elements.
webdav.ERROR_KIND as string
The kind of every error the module throws.
webdav.MAX_WALK as int
The most entries walk collects before it refuses.