一个 golang WebDAV 客户端库和命令行工具。
A pure Golang WebDAV client library that comes with a reference implementation.
Our gowebdav library allows to perform following actions on the remote WebDAV server:
It also provides an authentication API that makes it easy to encapsulate and control complex authentication challenges. The default implementation negotiates the algorithm based on the user's preferences and the methods offered by the remote server.
Out-of-box authentication support for:
First of all you should create Client instance using NewClient() function:
root := "https://webdav.mydomain.me"
user := "user"
password := "password"
c := gowebdav.NewClient(root, user, password)
c.Connect()
// kick of your work!After you can use this Client to perform actions, described below.
NOTICE: We will not check for errors in the examples, to focus you on the gowebdav library's code, but you should do it in your code!
err := c.Mkdir("folder", 0644)In case you want to create several folders you can use c.MkdirAll():
err := c.MkdirAll("folder/subfolder/subfolder2", 0644)files, _ := c.ReadDir("folder/subfolder")
for _, file := range files {
//notice that [file] has os.FileInfo type
fmt.Println(file.Name())
}webdavFilePath := "folder/subfolder/file.txt"
localFilePath := "/tmp/webdav/file.txt"
bytes, _ := c.Read(webdavFilePath)
os.WriteFile(localFilePath, bytes, 0644)Also you can use c.ReadStream() method:
webdavFilePath := "folder/subfolder/file.txt"
localFilePath := "/tmp/webdav/file.txt"
reader, _ := c.ReadStream(webdavFilePath)
file, _ := os.Create(localFilePath)
defer file.Close()
io.Copy(file, reader)webdavFilePath := "folder/subfolder/file.txt"
localFilePath := "/tmp/webdav/file.txt"
bytes, _ := os.ReadFile(localFilePath)
c.Write(webdavFilePath, bytes, 0644)webdavFilePath := "folder/subfolder/file.txt"
localFilePath := "/tmp/webdav/file.txt"
file, _ := os.Open(localFilePath)
defer file.Close()
c.WriteStream(webdavFilePath, file, 0644)For non-seekable stream, this will read data into memory first to discover content length.
webdavFilePath := "folder/subfolder/file.txt"
bytes := []byte{0x20, 0x20}
c.WriteStreamWithLength(webdavFilePath, bytes.NewBuffer(bytes), int64(len(data)), 0644)webdavFilePath := "folder/subfolder/file.txt"
info := c.Stat(webdavFilePath)
//notice that [info] has os.FileInfo type
fmt.Println(info)oldPath := "folder/subfolder/file.txt"
newPath := "folder/subfolder/moved.txt"
isOverwrite := true
c.Rename(oldPath, newPath, isOverwrite)oldPath := "folder/subfolder/file.txt"
newPath := "folder/subfolder/file-copy.txt"
isOverwrite := true
c.Copy(oldPath, newPath, isOverwrite)webdavFilePath := "folder/subfolder/file.txt"
c.Remove(webdavFilePath)More details about WebDAV server you can read from following resources:
NOTICE: RFC 2518 is obsoleted by RFC 4918 in June 2007
All contributing are welcome. If you have any suggestions or find some bug - please create an Issue to let us make this project better. We appreciate your help!
This library is distributed under the BSD 3-Clause license found in the LICENSE file.
import "github.com/studio-b12/gowebdav"
Package gowebdav is a WebDAV client library with a command line tool included.
auth.go basicAuth.go client.go digestAuth.go doc.go errors.go file.go netrc.go passportAuth.go requests.go utils.go
const XInhibitRedirect = "X-Gowebdav-Inhibit-Redirect"var ErrAuthChanged = errors.New("authentication failed, change algorithm")ErrAuthChanged must be returned from the Verify method as an error to trigger a re-authentication / negotiation with a new authenticator.
var ErrTooManyRedirects = errors.New("stopped after 10 redirects")ErrTooMan
暂无开放 Issues,或尚未同步最近议题。