WebDAV 配置及相关工具

最近在项目中安装和调试服务器,杯具的是,服务器是内网地址,而且不可以直接SSH、SFTP,只能通过中间一台linux作为跳板,然后在SSH命令行里去操作目标机器。

如果只是命令行操作也就无所谓了,但是还要经常传输文件,在跳板机上SSH,SFTP,SCP命令切换过来切换过去,累死了,有没有更好的办法?

依稀记得N年前折腾过一个通过http协议操作服务器文件的玩意,那就是WebDAV。

 

科普开始。WebDAV (Web-based Distributed Authoring and Versioning) 一种基于 HTTP 1.1协议的通信协议。它扩展了HTTP 1.1,在GET、POST、HEAD等几个HTTP标准方法以外添加了一些新的方法,使应用程序可直接对Web Server直接读写,并支持写文件锁定(Locking)及解锁(Unlock),还可以支持文件的版本控制。更多说明,请自行百度谷歌。比如,可以通过打开 http://127.0.0.1/uploads/ 来操作服务器上指定目录的文件,非常方便,解决了某些单位网络端口和防火墙的限制。

 

WebDAV配置

 

WebDAV服务端,目前我只折腾过Apache httpd,其他的我还不了解。从apache httpd官网下载好httpd 2.x版本,下载安装,完毕之后,打开httpd.conf文件,将最后几行的一个注释去掉。

1 # Distributed authoring and versioning (WebDAV)
2 Include conf/extra/httpd-dav.conf

然后编辑conf/extra/httpd-dav.conf文件

#
# Distributed authoring and versioning (WebDAV)
# modified by longware
# Required modules: mod_dav, mod_dav_fs, mod_setenvif, mod_alias
#                   mod_auth_digest, mod_authn_file
#
#LoadModule dav_module modules/mod_dav.so
#LoadModule dav_fs_module modules/mod_dav_fs.so
#LoadModule alias_module modules/mod_alias.so
#LoadModule auth_digest_module modules/mod_auth_digest.so
#LoadModule authn_file_module modules/mod_authn_file.so

# The following example gives DAV write access to a directory called
# "uploads" under the ServerRoot directory.
#
# The User/Group specified in httpd.conf needs to have write permissions
# on the directory where the DavLockDB is placed and on any directory where
# "Dav On" is specified.

DavLockDB "D:/WebServer/apache/var/DavLock"

Alias /uploads "D:/WebServer/apache/uploads"

<Directory "D:/WebServer/apache/uploads">
    Dav On

    Order Allow,Deny
    Allow from all

    AuthType Digest
    AuthName DAV-upload

    # You can use the htdigest program to create the password database:
    #   htdigest -c "D:/WebServer/apache/user.passwd" DAV-upload admin
    AuthUserFile "D:/WebServer/apache/user.passwd"
    AuthDigestProvider file

    # Allow universal read-access, but writes are restricted
    # to the admin user.
    <LimitExcept GET OPTIONS>
        require user admin
    </LimitExcept>
</Directory>

#
# The following directives disable redirects on non-GET requests for
# a directory that does not include the trailing slash.  This fixes a
# problem with several clients that do not appropriately handle
# redirects for folders with DAV methods.
#
BrowserMatch "Microsoft Data Access Internet Publishing Provider" redirect-carefully
BrowserMatch "MS FrontPage" redirect-carefully
BrowserMatch "^WebDrive" redirect-carefully
BrowserMatch "^WebDAVFS/1.[0123]" redirect-carefully
BrowserMatch "^gnome-vfs/1.0" redirect-carefully
BrowserMatch "^XML Spy" redirect-carefully
BrowserMatch "^Dreamweaver-WebDAV-SCM1" redirect-carefully

上面的代码中,LoadModule部分,请根据自己情况开启,如果主httpd.conf文件中都开启了,此处就不用开启,反之,在这里要加上LoadModule。

然后在apache的bin目录里,在cmd模式里,执行命令 

htdigest -c "D:/WebServer/apache/user.passwd" DAV-upload admin

会提示输入密码,此处就会生成一个用户名和密码对应的库文件。

然后重启apache,在浏览器地址栏输入http://127.0.0.1/uploads/,如果看到403禁止访问,应该就是配置成功了。

此配置文件适用于Linux系统,本人已配置成功,之前折腾了很久,走了弯路,汗!如果想成功在客户端操作文件,必须要将apache的默认运行用户daemon和目标文件夹设置为同一用户,或者同一组,或者自己更改apache的默认用户。

 

WebDAV客户端

 

1、最简便的客户端工具,就是windows的资源管理器(建议win7以上操作系统),打开我的电脑,右键“添加一个网络位置”,然后根据向导,输入地址http://127.0.0.1/uploads/,需要验证的时候,输入口令,就在我的电脑里创建了一个网络文件夹,双击打开,就可以自由操作文件了。

使用windows的资源管理器的优点是方便,缺点是,我感觉操作和响应有点慢,于是乎,我在寻找其他工具。

2、WINSCP 5.7.3

要5.7以上版本,之前的版本不支持。winscp界面友好,操作很方便,推荐。

3、Beyond Compare 4

如果你经常比较文件和文件夹,推荐Beyond Compare,我从2.0开始用的,非常好。进行比较文件夹时,可以选择其他文件系统,选择webdav即可。Beyond Compare 4才支持webdav,以前的版本不支持。

4、其他

BitKinex、Cyberduck、WebDrive、DAVExplorer、FarNetBox、AnyClient等等,我试用了下,感觉都怎么的不那么好用,要不UI不够友好,要不功能不够强大。

更多工具参考这里,有些free有些收费。

http://en.wikipedia.org/wiki/Comparison_of_WebDAV_software

http://webdav.org/projects/

 

posted @ 2015-05-18 12:22  longware  阅读(7089)  评论(0编辑  收藏  举报