A golang WebDAV client library and command line tool.
Go to file
2019-01-03 20:40:47 +02:00
.github/ISSUE_TEMPLATE Update issue templates 2018-06-19 08:36:40 +02:00
cmd/gowebdav fix uploading file with wrong content. close #30 2019-01-03 20:40:47 +02:00
.gitignore .gitignore was expanded (#18) 2018-07-08 14:27:10 +02:00
.travis.yml Creating parent collection method was added (#22) 2018-07-14 01:48:30 +02:00
basicAuth.go Add Authenticator interface and Digest auth support 2018-05-25 22:40:13 +02:00
client.go Merge remote-tracking branch 'upstream/master' 2018-07-17 14:00:43 +03:00
digestAuth.go fmt 2018-07-13 12:12:09 +02:00
doc.go docs 2018-05-25 23:59:53 +02:00
file.go Fetch ContentType and ETag 2018-05-17 01:22:58 +02:00
LICENSE add NEW BSD Liscense 2014-10-23 10:37:45 +02:00
Makefile docs 2018-05-25 23:59:53 +02:00
netrc.go add ability to read login / pw from ~/.netrc 2018-05-26 01:36:44 +02:00
README.md links was updated in readme file. Related to studio-b12/gowebdav#27 2018-10-24 14:05:51 +03:00
requests.go use 'application/xml' instead of 'text/xml'. related with (1) in #15 2018-12-29 22:04:04 +02:00
utils_test.go Escape URL 2018-05-23 13:41:06 +02:00
utils.go Escape URL 2018-05-23 13:41:06 +02:00

GoWebDAV

Build Status GoDoc Go Report Card

A golang WebDAV client library.

Main features

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

Usage

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)

After you can use this Client to perform actions, described below.

NOTICE: we will not check errors in examples, to focus you on the gowebdav library's code, but you should do it in your code!

Create path on a WebDAV server

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)

Get files list

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

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

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

Download file via reader

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)

Upload file from byte array

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

bytes, _ := ioutil.ReadFile(localFilePath)

c.Write(webdavFilePath, bytes, 0644)

Upload file via writer

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

file, _ := os.Open(localFilePath)
defer file.Close()

c.WriteStream(webdavFilePath, file, 0644)

Get information about specified file/folder

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

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

Move file to another location

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

c.Rename(oldPath, newPath, isOverwrite)

Copy file to another location

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

c.Copy(oldPath, newPath, isOverwrite)

Delete file

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

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.