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/

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM