uploading files to a webdav SSL enabled server

Discussion in 'Python' started by rbt, May 25, 2005.

  1. rbt

    rbt Guest

    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
    rbt, May 25, 2005
    #1
    1. Advertising

  2. rbt

    Peter Hansen Guest

    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
    Peter Hansen, May 25, 2005
    #2
    1. Advertising

  3. rbt

    Paul Boddie Guest

    rbt <> wrote in message news:<d720om$3cr$>...
    > 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
    Paul Boddie, May 26, 2005
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Gabor
    Replies:
    3
    Views:
    601
    Jacob Yang [MSFT]
    Aug 26, 2003
  2. Dung Ping
    Replies:
    10
    Views:
    946
    Chaddy2222
    Jan 16, 2006
  3. Frederik Vanrenterghem

    ssl-enabled python for arm linux

    Frederik Vanrenterghem, May 4, 2005, in forum: Python
    Replies:
    0
    Views:
    731
    Frederik Vanrenterghem
    May 4, 2005
  4. Brad Tilley

    webdav client with SSL

    Brad Tilley, Oct 24, 2006, in forum: Ruby
    Replies:
    0
    Views:
    410
    Brad Tilley
    Oct 24, 2006
  5. Michael Dichtl

    WebDAV: Connect Ruby to a WebDAV Server

    Michael Dichtl, Jul 9, 2007, in forum: Ruby
    Replies:
    7
    Views:
    869
    Rob Biedenharn
    Jul 9, 2007
Loading...

Share This Page