百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
G

gowebdav

> 开发工具
开源

一个 golang WebDAV 客户端库和命令行工具。

368 stars0 点赞1 次浏览
访问官网GitHub

工具介绍

一个 golang WebDAV 客户端库和命令行工具。

GoWebDAV

A pure Golang WebDAV client library that comes with a reference implementation.

Features at a glance

Our gowebdav library allows to perform following actions on the remote WebDAV server:

  • create path
  • get files list
  • download file
  • upload file
  • get information about specified file/folder
  • move file to another location
  • copy file to another location
  • delete file

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:

  • BasicAuth
  • DigestAuth
  • MS-PASS
  • WIP Kerberos
  • WIP Bearer Token

Usage

First of all you should create Client instance using NewClient() function:

go
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!

Create path on a WebDAV server

go
err := c.Mkdir("folder", 0644)

In case you want to create several folders you can use c.MkdirAll():

go
err := c.MkdirAll("folder/subfolder/subfolder2", 0644)

Get files list

go
files, _ := c.ReadDir("folder/subfolder")
for _, file := range files {
    //notice that [file] has os.FileInfo type
    fmt.Println(file.Name())
}

Download file to byte array

go
webdavFilePath := "folder/subfolder/file.txt"
localFilePath := "/tmp/webdav/file.txt"

bytes, _ := c.Read(webdavFilePath)
os.WriteFile(localFilePath, bytes, 0644)

Download file via reader

Also you can use c.ReadStream() method:

go
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)

Upload file from byte array

go
webdavFilePath := "folder/subfolder/file.txt"
localFilePath := "/tmp/webdav/file.txt"

bytes, _ := os.ReadFile(localFilePath)

c.Write(webdavFilePath, bytes, 0644)

Upload file via writer

go
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.

Upload file via writer with known length

go
webdavFilePath := "folder/subfolder/file.txt"

bytes := []byte{0x20, 0x20}

c.WriteStreamWithLength(webdavFilePath, bytes.NewBuffer(bytes), int64(len(data)), 0644)

Get information about specified file/folder

go
webdavFilePath := "folder/subfolder/file.txt"

info := c.Stat(webdavFilePath)
//notice that [info] has os.FileInfo type
fmt.Println(info)

Move file to another location

go
oldPath := "folder/subfolder/file.txt"
newPath := "folder/subfolder/moved.txt"
isOverwrite := true

c.Rename(oldPath, newPath, isOverwrite)

Copy file to another location

go
oldPath := "folder/subfolder/file.txt"
newPath := "folder/subfolder/file-copy.txt"
isOverwrite := true

c.Copy(oldPath, newPath, isOverwrite)

Delete file

go
webdavFilePath := "folder/subfolder/file.txt"

c.Remove(webdavFilePath)

Links

More details about WebDAV server you can read from following resources:

  • RFC 4918 - HTTP Extensions for Web Distributed Authoring and Versioning (WebDAV)
  • RFC 5689 - Extended MKCOL for Web Distributed Authoring and Versioning (WebDAV)
  • RFC 2616 - HTTP/1.1 Status Code Definitions
  • WebDav: Next Generation Collaborative Web Authoring By Lisa Dusseaul

NOTICE: RFC 2518 is obsoleted by RFC 4918 in June 2007

Contributing

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!

License

This library is distributed under the BSD 3-Clause license found in the LICENSE file.

Stargazers over time

API

import "github.com/studio-b12/gowebdav"

  • Overview
  • Index
  • Examples
  • Subdirectories

Overview

Package gowebdav is a WebDAV client library with a command line tool included.

Index

  • Constants
  • Variables
  • func FixSlash(s string) string
  • func FixSlashes(s string) string
  • func IsErrCode(err error, code int) bool
  • func IsErrNotFound(err error) bool
  • func Join(path0 string, path1 string) string
  • func NewPathError(op string, path string, statusCode int) error
  • func NewPathErrorErr(op string, path string, err error) error
  • func PathEscape(path string) string
  • func ReadConfig(uri, netrc string) (string, string)
  • func String(r io.Reader) string
  • type AuthFactory
  • type Authenticator
    • func NewDigestAuth(login, secret string, rs *http.Response) (Authenticator, error)
    • func NewPassportAuth(c *http.Client, user, pw, partnerURL string, header *http.Header) (Authenticator, error)
  • type Authorizer
    • func NewAutoAuth(login string, secret string) Authorizer
    • func NewEmptyAuth() Authorizer
    • func NewPreemptiveAuth(auth Authenticator) Authorizer
  • type BasicAuth
    • func (b *BasicAuth) Authorize(c *http.Client, rq *http.Request, path string) error
    • func (b *BasicAuth) Clone() Authenticator
    • func (b *BasicAuth) Close() error
    • func (b *BasicAuth) String() string
    • func (b *BasicAuth) Verify(c *http.Client, rs *http.Response, path string) (redo bool, err error)
  • type Client
    • func NewAuthClient(uri string, auth Authorizer) *Client
    • func NewClient(uri, user, pw string) *Client
    • func (c *Client) Connect() error
    • func (c *Client) Copy(oldpath, newpath string, overwrite bool) error
    • func (c *Client) Mkdir(path string, _ os.FileMode) (err error)
    • func (c *Client) MkdirAll(path string, _ os.FileMode) (err error)
    • func (c *Client) Read(path string) ([]byte, error)
    • func (c *Client) ReadDir(path string) ([]os.FileInfo, error)
    • func (c *Client) ReadStream(path string) (io.ReadCloser, error)
    • func (c *Client) ReadStreamRange(path string, offset, length int64) (io.ReadCloser, error)
    • func (c *Client) Remove(path string) error
    • func (c *Client) RemoveAll(path string) error
    • func (c *Client) Rename(oldpath, newpath string, overwrite bool) error
    • func (c *Client) SetHeader(key, value string)
    • func (c *Client) SetInterceptor(interceptor func(method string, rq *http.Request))
    • func (c *Client) SetJar(jar http.CookieJar)
    • func (c *Client) SetTimeout(timeout time.Duration)
    • func (c *Client) SetTransport(transport http.RoundTripper)
    • func (c *Client) Stat(path string) (os.FileInfo, error)
    • func (c *Client) Write(path string, data []byte, _ os.FileMode) (err error)
    • func (c *Client) WriteStream(path string, stream io.Reader, _ os.FileMode) (err error)
    • func (c *Client) WriteStreamWithLength(path string, stream io.Reader, contentLength int64, _ os.FileMode) (err error)
  • type DigestAuth
    • func (d *DigestAuth) Authorize(c *http.Client, rq *http.Request, path string) error
    • func (d *DigestAuth) Clone() Authenticator
    • func (d *DigestAuth) Close() error
    • func (d *DigestAuth) String() string
    • func (d *DigestAuth) Verify(c *http.Client, rs *http.Response, path string) (redo bool, err error)
  • type File
    • func (f File) ContentType() string
    • func (f File) ETag() string
    • func (f File) IsDir() bool
    • func (f File) ModTime() time.Time
    • func (f File) Mode() os.FileMode
    • func (f File) Name() string
    • func (f File) Path() string
    • func (f File) Size() int64
    • func (f File) String() string
    • func (f File) Sys() interface{}
  • type PassportAuth
    • func (p *PassportAuth) Authorize(c *http.Client, rq *http.Request, path string) error
    • func (p *PassportAuth) Clone() Authenticator
    • func (p *PassportAuth) Close() error
    • func (p *PassportAuth) String() string
    • func (p *PassportAuth) Verify(c *http.Client, rs *http.Response, path string) (redo bool, err error)
  • type StatusError
    • func (se StatusError) Error() string
Examples
  • PathEscape
Package files

auth.go basicAuth.go client.go digestAuth.go doc.go errors.go file.go netrc.go passportAuth.go requests.go utils.go

Constants

go
const XInhibitRedirect = "X-Gowebdav-Inhibit-Redirect"

Variables

go
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.

go
var ErrTooManyRedirects = errors.New("stopped after 10 redirects")

ErrTooMan

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

Gocliclientgolanglibrary

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月17日
分类开发工具
定价开源

> 相关工具

V
VS Code
流行的开源代码编辑器
G
Git
分布式版本控制系统
V
Vite
下一代前端构建工具