Welcome, guest | Sign In | My Account | Store | Cart

An extremely simple example of using httplib to write a file to a WebDAV server. This version does not use any authentication mechanism.

Python, 9 lines
1
2
3
4
5
6
7
8
9
# puts a 'Hello, World!' file at http://myserver.com/dav/testfile

import httplib
dav_server = httplib.HTTPConnection('myserver.com')
dav_server.request('PUT', '/dav/testfile', 'Hello, World!')
dav_response = dav_server.getresponse()
dav_server.close()
if not (200 <= dav_response.status < 300):
	raise Exception(dav_response.read())

This is about the barest-version of code that will write to a WebDAV location that there is. Its biggest deficiency is that it doesn't do any form of http authentication and generally an unprotected WebDAV server is a bad idea.

It is possible to protect a WebDAV directory such that it will only allow certain IP addresses to access it and this is how I use this bit of code; I have a bunch of servers processing data and periodically they compute some value and write it to a centralized location using WebDAV.