uploading files to a webdav SSL enabled server

R

rbt

Has anyone used pure python to upload files to a webdav server over SSL?
I have no control over the server. I can access it with all of the
various webdav GUIs such as Konqueror, Cadaver, etc. by using a URL like
this:

webdavs://dav.hostname.com/user_name/uploads

My goal is to upload files automatically with a python script. The
server requires authentication over SSL which I can do with urllib2 like
this:

def auth_against_url(url, username, password):

# This is a slightly modified version that I found here:
# http://simon.incutio.com/archive/2004/07/15/instant

import urllib2
import base64
request = urllib2.Request(url)
b64 = base64.encodestring('%s:%s' % (username, password))[:-1]
request.add_header('Authorization', 'Basic %s' % b64)
try:
f = urllib2.urlopen(request)
print f.read()
f.close()
return True
except urllib2.HTTPError, e:
print e
return False

auth_against_url('https://dav.hostname.com/user_name/uploads',\
str.strip(raw_input('Enter User ID: ')),\
str.strip(raw_input('Enter Password: ')))

If urllib2 supported webdav, I think I'd be in business, but it doesn't.
Any one who can provide pointers on this? I've googled around to no
avail. I've began playing with Perl's HTTP::DAV and somone reccomended
PHP's curl functions as well, but I wanted to try this in Python first.

Many thanks,
rbt
 
P

Peter Hansen

rbt said:
Has anyone used pure python to upload files to a webdav server over SSL?

We were not using SSL at the time (since it wasn't supported in standard
Python, as I recall), but we successfully used the webdav client that
was part of Zope a few years ago. I suspect you could adapt it to use
the new SSL support relatively easily. Check back for version 2.4 or so
if you can't find it in the latest Zopes. (I haven't looked at Zope for
a few years now, so I don't know whether it's still included.)

-Peter
 
P

Paul Boddie

rbt said:
Has anyone used pure python to upload files to a webdav server over SSL?
I have no control over the server. I can access it with all of the
various webdav GUIs such as Konqueror, Cadaver, etc. by using a URL like
this:

webdavs://dav.hostname.com/user_name/uploads

I suppose it would be nice if urllib(2) supported WebDAV in this way,
but you should still be able to use httplib to interact with the
server. Uploading in WebDAV is just a matter of doing an HTTP PUT if I
recall correctly, and I don't think that any of the special status
codes or responses are involved; in this sense WebDAV overlaps with
traditional HTTP.

[...]
If urllib2 supported webdav, I think I'd be in business, but it doesn't.
Any one who can provide pointers on this? I've googled around to no
avail. I've began playing with Perl's HTTP::DAV and somone reccomended
PHP's curl functions as well, but I wanted to try this in Python first.

Searching for "DAV Python" revealed the following projects:

http://www.lyra.org/greg/python/
http://cvs.infrae.com/packages/pydavclient/dav/

Really it's just a matter of talking HTTP to a server and parsing the
special messages that are returned for certain request methods, but
you may not even need to do that if you're just uploading files.

Paul
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,020
Latest member
GenesisGai

Latest Threads

Top