Webdav API,resource API and wdc for WebDAV服务器(Yandex.Disk,Dropbox,Google Disk,Box,4shared等)
webdavclient的Python项目详细描述
WebDAVClient
包WebDAVClient提供了简单方便的 WebDAV服务器(yandex.drive、dropbox、google drive、box、4shared, 等等)。这个包包括以下组件:webdav api, 资源API和WDC。
可以找到项目的源代码 here
安装和升级
安装
- Linux
$ sudo apt-get install libxml2-dev libxslt-dev python-dev $ sudo apt-get install libcurl4-openssl-dev python-pycurl $ sudo easy_install webdavclient
- MacOS
curl https://bootstrap.pypa.io/ez_setup.py -o - | python python setup.py install --prefix=/opt/setuptools sudo easy_install webdavclient
更新
$ sudo pip install -U webdavclient
WebDAV API
webdav api是一组使用云存储的webdav方法。这个 set包含以下方法:check,free,info, list,mkdir,clean,copy,move,download, upload、publish和unpublish。
配置客户端
配置与WEVDAV服务器的客户端连接所需的密钥是 webdav_主机名和webdav_登录名、webdav和密码。
importwebdav.clientaswcoptions={'webdav_hostname':"https://webdav.server.ru",'webdav_login':"login",'webdav_password':"password"}client=wc.Client(options)
当代理服务器需要指定通过它连接的设置时。
importwebdav.clientaswcoptions={'webdav_hostname':"https://webdav.server.ru",'webdav_login':"w_login",'webdav_password':"w_password",'proxy_hostname':"http://127.0.0.1:8080",'proxy_login':"p_login",'proxy_password':"p_password"}client=wc.Client(options)
如果要使用证书和私钥的证书路径 定义如下:
importwebdav.clientaswcoptions={'webdav_hostname':"https://webdav.server.ru",'webdav_login':"w_login",'webdav_password':"w_password",'cert_path':"/etc/ssl/certs/certificate.crt",'key_path':"/etc/ssl/private/certificate.key"}client=wc.Client(options)
或者您想限制速度或打开详细模式:
options={...'recv_speed':3000000,'send_speed':3000000,'verbose':True}client=wc.Client(options)
同步方法
//Checkingexistenceoftheresourceclient.check("dir1/file1")client.check("dir1")
//Getinformationabouttheresourceclient.info("dir1/file1")client.info("dir1/")
//Checkfreespacefree_size=client.free()
//Getalistofresourcesfiles1=client.list()files2=client.list("dir1")
//Createdirectoryclient.mkdir("dir1/dir2")
//Deleteresourceclient.clean("dir1/dir2")
//Copyresourceclient.copy(remote_path_from="dir1/file1",remote_path_to="dir2/file1")client.copy(remote_path_from="dir2",remote_path_to="dir3")
//Moveresourceclient.move(remote_path_from="dir1/file1",remote_path_to="dir2/file1")client.move(remote_path_from="dir2",remote_path_to="dir3")
//Moveresourceclient.download_sync(remote_path="dir1/file1",local_path="~/Downloads/file1")client.download_sync(remote_path="dir1/dir2/",local_path="~/Downloads/dir2/")
//Unloadresourceclient.upload_sync(remote_path="dir1/file1",local_path="~/Documents/file1")client.upload_sync(remote_path="dir1/dir2/",local_path="~/Documents/dir2/")
//Publishtheresourcelink=client.publish("dir1/file1")link=client.publish("dir2")
//Unpublishresourceclient.unpublish("dir1/file1")client.unpublish("dir2")
//Exceptionhandlingfromwebdav.clientimportWebDavExceptiontry:...exceptWebDavExceptionasexception:...
//Getthemissingfilesclient.pull(remote_directory='dir1',local_directory='~/Documents/dir1')
//Sendmissingfilesclient.push(remote_directory='dir1',local_directory='~/Documents/dir1')
异步方法
//Loadresourcekwargs={'remote_path':"dir1/file1",'local_path':"~/Downloads/file1",'callback':callback}client.download_async(**kwargs)kwargs={'remote_path':"dir1/dir2/",'local_path':"~/Downloads/dir2/",'callback':callback}client.download_async(**kwargs)
//Unloadresourcekwargs={'remote_path':"dir1/file1",'local_path':"~/Downloads/file1",'callback':callback}client.upload_async(**kwargs)kwargs={'remote_path':"dir1/dir2/",'local_path':"~/Downloads/dir2/",'callback':callback}client.upload_async(**kwargs)
资源API
使用支持云级别的oop概念的资源api 资源。
//Getaresourceres1=client.resource("dir1/file1")
//Workwiththeresourceres1.rename("file2")res1.move("dir1/file2")res1.copy("dir2/file1")info=res1.info()res1.read_from(buffer)res1.read(local_path="~/Documents/file1")res1.read_async(local_path="~/Documents/file1",callback)res1.write_to(buffer)res1.write(local_path="~/Downloads/file1")res1.write_async(local_path="~/Downloads/file1",callback)
WDC
WDC-一个跨平台实用程序,提供了 WebDAV服务器就在您的控制台上。除了全部 webdav api中方法的实现,还添加了方法内容 同步本地和远程目录。
身份验证
- basic认证
$ wdc login https://wedbav.server.ru -p http://127.0.0.1:8080 webdav_login: w_login webdav_password: w_password proxy_login: p_login proxy_password: p_password success
- 使用OAuth令牌授权应用程序*
$ wdc login https://wedbav.server.ru -p http://127.0.0.1:8080 --token xxxxxxxxxxxxxxxxxx proxy_login: p_login proxy_password: p_password success
还有其他键--root[-r],--cert-path[-c]和 --key-path[-k]。
实用程序
$ wdc check success $ wdc check file1 not success $ wdc free 245234120344 $ wdc ls dir1 file1 ... fileN $ wdc mkdir dir2 $ wdc copy dir1/file1 -t dir2/file1 $ wdc move dir2/file1 -t dir2/file2 $ wdc download dir1/file1 -t ~/Downloads/file1 $ wdc download dir1/ -t ~/Downloads/dir1/ $ wdc upload dir2/file2 -f ~/Documents/file1 $ wdc upload dir2/ -f ~/Documents/ $ wdc publish di2/file2 https://yadi.sk/i/vWtTUcBucAc6k $ wdc unpublish dir2/file2 $ wdc pull dir1/ -t ~/Documents/dir1/ $ wdc push dir1/ -f ~/Documents/dir1/ $ wdc info dir1/file1 {'name': 'file1', 'modified': 'Thu, 23 Oct 2014 16:16:37 GMT', 'size': '3460064', 'created': '2014-10-23T16:16:37Z'}
WebDAV服务器
支持该协议的最流行的基于云的存储库 webdav可以归为yandex.drive、dropbox、google drive、box和 4共享。访问数据存储库,通过访问 互联网。如果需要本地位置和云存储,可以部署 您自己的WebDAV服务器。
本地WebDAV服务器
要部署本地WebDAV服务器,使用Docker容器非常容易 而且很快。要查看本地部署的示例,webdav服务器可以 参与项目 webdav-server-docker。
支持的方法
Servers | free | info | list | mkdir | clean | copy | move | download | upload |
---|---|---|---|---|---|---|---|---|---|
Yandex.Disk | + | + | + | + | + | + | + | + | + |
Dropbox | - | + | + | + | + | + | + | + | + |
Google Drive | - | + | + | + | + | - | - | + | + |
Box | + | + | + | + | + | + | + | + | + |
4shared | - | + | + | + | + | - | - | + | + |
Webdavserver | - | + | + | + | + | - | - | + | + |
publish和unpublish方法只支持yandex.disk。
配置连接
通过WebDAV使用云存储Dropbox和Google Drive 协议,您必须使用WebDAV服务器DropDAV和DAV Pocket, 分别是。
WebDAV服务器的设置列表:
webdav-servers:-yandexhostname:https://webdav.yandex.rulogin:#login_for_yandexpassword:#pass_for_yandex-dropboxhostname:https://dav.dropdav.comlogin:#login_for dropdavpassword:#pass_for_dropdav-googlehostname:https://dav-pocket.appspot.comroot:docsologin:#login_for_dav-pocketpassword:#pass_for_dav-pocket-boxhostname:https://dav.box.comroot:davlogin:#login_for_boxpassword:#pass_for_box-4sharedhostname:https://webdav.4shared.comlogin:#login_for_4sharedpassword:#pass_for_4shared
自动完成
对于macos或旧的unix系统,您需要更新bash。
brew install bash chsh brew install bash-completion
可以全局启用自动完成功能
sudo activate-global-python-argcomplete
或本地
#.bashrc eval"$(register-python-argcomplete wdc)"