WebDAV的Python客户端库

时间:2009-10-08 17:38:32

标签: python client webdav

我想在我的应用程序中实现一项功能,在WebDAV服务器上上传和操作文件。我正在寻找一个成熟的Python库,它可以提供类似于os.*模块的接口来处理远程文件。谷歌搜索已经为Python中的WebDAV提供了一些选项,但我想知道这些日子有哪些更广泛使用。

7 个答案:

答案 0 :(得分:48)

令人遗憾的是,对于这个问题("使用什么Python webdav库?"),这肯定是一个人感兴趣的,不相关的答案被接受了(" don& #39;使用Python webdav库")。好吧,Stackexchange上常见的问题。

对于那些寻找真实答案并且在原始问题中给出要求的人(简单的API类似于" os"模块),我可能会建议easywebdav,这很容易API甚至简单的实现,提供上传/下载和少量文件/目录管理方法。由于实现简单,它到目前为止还不支持目录列表,但是它的错误是filed,作者打算添加它。

答案 1 :(得分:9)

我只是有类似的需求,最后根据我的需要测试了一些Python WebDAV客户端(从WebDAV服务器上传和下载文件)。以下是我的经历总结:

1)对我有用的是python-webdav-lib

没有太多文档,但快速查看代码(特别是示例)就足以弄清楚如何让它适用于我。

2)PyDAV 0.21(我发现的最新版本)不适用于Python 2.6,因为它使用字符串作为例外。我没有尝试解决这个问题,期待以后进一步的不兼容性。

3)davclient 0.2.0。我看了它但没有进一步探索,因为文档没有提到我正在寻找的API级别(文件上传和下载)。

4)Python_WebDAV_Library-0.3.0。似乎没有任何上传功能。

答案 2 :(得分:2)

import easywebdav

webdav = easywebdav.connect(
    host='dav.dumptruck.goldenfrog.com',
    username='_snip_',
    port=443,
    protocol="https",
    password='_snip_')

_file = "test.py"

print webdav.cd("/dav/")
# print webdav._get_url("")
# print webdav.ls()
# print webdav.exists("/dav/test.py")
# print webdav.exists("ECS.zip")
# print webdav.download(_file, "./"+_file)
print webdav.upload("./test.py", "test.py")

答案 3 :(得分:1)

显然你正在寻找一个WebDAV客户端库。

不确定gazillion如何出现,似乎以下2看起来相关:

答案 4 :(得分:0)

我不知道具体但是,根据您的平台,通过文件系统安装和访问WebDAV服务文件可能更简单。那里有davfs2,一些操作系统,如Mac OS X,内置了WebDAV文件系统支持。

答案 5 :(得分:0)

我没有任何这些库的经验,但Python包索引(“PyPi”)lists quite a few webdav modules

答案 6 :(得分:0)

安装:

$ sudo apt-get install libxml2-dev libxslt-dev python-dev
$ sudo apt-get install libcurl4-openssl-dev python-pycurl
$ sudo easy_install webdavclient

示例:

import webdav.client as wc

options = {
  'webdav_hostname': "https://webdav.server.ru",
  'webdav_login': "login",
  'webdav_password': "password"
}

client = wc.Client(options)

client.check("dir1/file1")
client.info("dir1/file1")

files = client.list()
free_size = client.free()

client.mkdir("dir1/dir2")
client.clean("dir1/dir2")

client.copy(remote_path_from="dir1/file1", remote_path_to="dir2/file1")
client.move(remote_path_from="dir1/file1", remote_path_to="dir2/file1")

client.download_sync(remote_path="dir1/file1", local_path="~/Downloads/file1")
client.upload_sync(remote_path="dir1/file1", local_path="~/Documents/file1")
client.download_async(remote_path="dir1/file1", local_path="~/Downloads/file1", callback=callback)
client.upload_async(remote_path="dir1/file1", local_path="~/Documents/file1", callback=callback)

link = client.publish("dir1/file1")
client.unpublish("dir1/file1")

链接:

相关问题