470,612 Members | 2,180 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,612 developers. It's quick & easy.

uploading files to a webdav SSL enabled server

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
Jul 19 '05 #1
2 4725
rbt wrote:
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
Jul 19 '05 #2
rbt <rb*@athop1.ath.vt.edu> wrote in message news:<d7**********@solaris.cc.vt.edu>...
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
Jul 19 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Independentsoft | last post: by
reply views Thread by Michael G. Schneider | last post: by
6 posts views Thread by subscriptions | last post: by
2 posts views Thread by D. Shane Fowlkes | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.