gowebdav

package module
v0.0.0-...-3cd755d Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 13, 2018 License: BSD-3-Clause Imports: 17 Imported by: 0

README

GoWebDAV

Build Status GoDoc Go Report Card

A golang WebDAV client library and command line tool.

Install command line tool

go get -u github.com/studio-b12/gowebdav/cmd/gowebdav

Usage

$ gowebdav --help
Usage of gowebdav
  -X string
        Method:
                LS <PATH>
                STAT <PATH>

                MKDIR <PATH>
                MKDIRALL <PATH>

                GET <PATH> [<FILE>]
                PUT <PATH> [<FILE>]

                MV <OLD> <NEW>
                CP <OLD> <NEW>

                DEL <PATH>

  -netrc-file string
        read login from netrc file (default "~/.netrc")
  -pw string
        Password [ENV.PASSWORD]
  -root string
        WebDAV Endpoint [ENV.ROOT]
  -user string
        User [ENV.USER] (default "$USER")

gowebdav wrapper script

Create a wrapper script for example $EDITOR ./dav && chmod a+x ./dav for your server and use pass or similar tools to retrieve the password.

#!/bin/sh

ROOT="https://my.dav.server/" \
USER="foo" \
PASSWORD="$(pass dav/foo@my.dav.server)" \
gowebdav $@

Examples

Using the dav wrapper:

$ ./dav -X LS /

$ echo hi dav! > hello && ./dav -X PUT /hello

$ ./dav -X STAT /hello

$ ./dav -X PUT /hello_dav hello

$ ./dav -X GET /hello_dav

$ ./dav -X GET /hello_dav hello.txt

API

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

Overview

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

Index
Examples
Package files

basicAuth.go client.go digestAuth.go doc.go file.go netrc.go requests.go utils.go

func FixSlash
func FixSlash(s string) string

FixSlash appends a trailing / to our string

func FixSlashes
func FixSlashes(s string) string

FixSlashes appends and prepends a / if they are missing

func Join
func Join(path0 string, path1 string) string

Join joins two paths

func PathEscape
func PathEscape(path string) string

PathEscape escapes all segemnts of a given path

func ReadConfig
func ReadConfig(uri, netrc string) (string, string)

ReadConfig reads login and password configuration from ~/.netrc machine foo.com login username password 123456

func String
func String(r io.Reader) string

String pulls a string out of our io.Reader

type Authenticator
type Authenticator interface {
    Type() string
    User() string
    Pass() string
    Authorize(*Client, string, string)
}

Authenticator stub

type BasicAuth
type BasicAuth struct {
    // contains filtered or unexported fields
}

BasicAuth structure holds our credentials

func (*BasicAuth) Authorize
func (b *BasicAuth) Authorize(c *Client, method string, path string)

Authorize the current request

func (*BasicAuth) Pass
func (b *BasicAuth) Pass() string

Pass holds the BasicAuth password

func (*BasicAuth) Type
func (b *BasicAuth) Type() string

Type identifies the BasicAuthenticator

func (*BasicAuth) User
func (b *BasicAuth) User() string

User holds the BasicAuth username

type Client
type Client struct {
    // contains filtered or unexported fields
}

Client defines our structure

func NewClient
func NewClient(uri, user, pw string) *Client

NewClient creates a new instance of client

func (*Client) Connect
func (c *Client) Connect() error

Connect connects to our dav server

func (*Client) Copy
func (c *Client) Copy(oldpath, newpath string, overwrite bool) error

Copy copies a file from A to B

func (*Client) Mkdir
func (c *Client) Mkdir(path string, _ os.FileMode) error

Mkdir makes a directory

func (*Client) MkdirAll
func (c *Client) MkdirAll(path string, _ os.FileMode) error

MkdirAll like mkdir -p, but for webdav

func (*Client) Read
func (c *Client) Read(path string) ([]byte, error)

Read reads the contents of a remote file

func (*Client) ReadDir
func (c *Client) ReadDir(path string) ([]os.FileInfo, error)

ReadDir reads the contents of a remote directory

func (*Client) ReadStream
func (c *Client) ReadStream(path string) (io.ReadCloser, error)

ReadStream reads the stream for a given path

func (*Client) Remove
func (c *Client) Remove(path string) error

Remove removes a remote file

func (*Client) RemoveAll
func (c *Client) RemoveAll(path string) error

RemoveAll removes remote files

func (*Client) Rename
func (c *Client) Rename(oldpath, newpath string, overwrite bool) error

Rename moves a file from A to B

func (*Client) SetHeader
func (c *Client) SetHeader(key, value string)

SetHeader lets us set arbitrary headers for a given client

func (*Client) SetTimeout
func (c *Client) SetTimeout(timeout time.Duration)

SetTimeout exposes the ability to set a time limit for requests

func (*Client) SetTransport
func (c *Client) SetTransport(transport http.RoundTripper)

SetTransport exposes the ability to define custom transports

func (*Client) Stat
func (c *Client) Stat(path string) (os.FileInfo, error)

Stat returns the file stats for a specified path

func (*Client) Write
func (c *Client) Write(path string, data []byte, _ os.FileMode) error

Write writes data to a given path

func (*Client) WriteStream
func (c *Client) WriteStream(path string, stream io.Reader, _ os.FileMode) error

WriteStream writes a stream

type DigestAuth
type DigestAuth struct {
    // contains filtered or unexported fields
}

DigestAuth structure holds our credentials

func (*DigestAuth) Authorize
func (d *DigestAuth) Authorize(c *Client, method string, path string)

Authorize the current request

func (*DigestAuth) Pass
func (d *DigestAuth) Pass() string

Pass holds the DigestAuth password

func (*DigestAuth) Type
func (d *DigestAuth) Type() string

Type identifies the DigestAuthenticator

func (*DigestAuth) User
func (d *DigestAuth) User() string

User holds the DigestAuth username

type File
type File struct {
    // contains filtered or unexported fields
}

File is our structure for a given file

func (File) ContentType
func (f File) ContentType() string

ContentType returns the content type of a file

func (File) ETag
func (f File) ETag() string

ETag returns the ETag of a file

func (File) IsDir
func (f File) IsDir() bool

IsDir let us see if a given file is a directory or not

func (File) ModTime
func (f File) ModTime() time.Time

ModTime returns the modified time of a file

func (File) Mode
func (f File) Mode() os.FileMode

Mode will return the mode of a given file

func (File) Name
func (f File) Name() string

Name returns the name of a file

func (File) Size
func (f File) Size() int64

Size returns the size of a file

func (File) String
func (f File) String() string

String lets us see file information

func (File) Sys
func (f File) Sys() interface{}

Sys ????

type NoAuth
type NoAuth struct {
    // contains filtered or unexported fields
}

NoAuth structure holds our credentials

func (*NoAuth) Authorize
func (n *NoAuth) Authorize(c *Client, method string, path string)

Authorize the current request

func (*NoAuth) Pass
func (n *NoAuth) Pass() string

Pass returns the current password

func (*NoAuth) Type
func (n *NoAuth) Type() string

Type identifies the authenticator

func (*NoAuth) User
func (n *NoAuth) User() string

User returns the current user


Generated by godoc2md

Documentation

Overview

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

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func FixSlash

func FixSlash(s string) string

FixSlash appends a trailing / to our string

func FixSlashes

func FixSlashes(s string) string

FixSlashes appends and prepends a / if they are missing

func Join

func Join(path0 string, path1 string) string

Join joins two paths

func PathEscape

func PathEscape(path string) string

PathEscape escapes all segemnts of a given path

Example
fmt.Println(PathEscape(""))
fmt.Println(PathEscape("/"))
fmt.Println(PathEscape("/web"))
fmt.Println(PathEscape("/web/"))
fmt.Println(PathEscape("/w e b/d a v/s%u&c#k:s/"))
Output:


/
/web
/web/
/w%20e%20b/d%20a%20v/s%25u&c%23k:s/

func ReadConfig

func ReadConfig(uri, netrc string) (string, string)

ReadConfig reads login and password configuration from ~/.netrc machine foo.com login username password 123456

func String

func String(r io.Reader) string

String pulls a string out of our io.Reader

Types

type Authenticator

type Authenticator interface {
	Type() string
	User() string
	Pass() string
	Authorize(*Client, string, string)
}

Authenticator stub

type BasicAuth

type BasicAuth struct {
	// contains filtered or unexported fields
}

BasicAuth structure holds our credentials

func (*BasicAuth) Authorize

func (b *BasicAuth) Authorize(c *Client, method string, path string)

Authorize the current request

func (*BasicAuth) Pass

func (b *BasicAuth) Pass() string

Pass holds the BasicAuth password

func (*BasicAuth) Type

func (b *BasicAuth) Type() string

Type identifies the BasicAuthenticator

func (*BasicAuth) User

func (b *BasicAuth) User() string

User holds the BasicAuth username

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client defines our structure

func NewClient

func NewClient(uri, user, pw string) *Client

NewClient creates a new instance of client

func (*Client) Connect

func (c *Client) Connect() error

Connect connects to our dav server

func (*Client) Copy

func (c *Client) Copy(oldpath, newpath string, overwrite bool) error

Copy copies a file from A to B

func (*Client) Mkdir

func (c *Client) Mkdir(path string, _ os.FileMode) error

Mkdir makes a directory

func (*Client) MkdirAll

func (c *Client) MkdirAll(path string, _ os.FileMode) error

MkdirAll like mkdir -p, but for webdav

func (*Client) Read

func (c *Client) Read(path string) ([]byte, error)

Read reads the contents of a remote file

func (*Client) ReadDir

func (c *Client) ReadDir(path string) ([]os.FileInfo, error)

ReadDir reads the contents of a remote directory

func (*Client) ReadStream

func (c *Client) ReadStream(path string) (io.ReadCloser, error)

ReadStream reads the stream for a given path

func (*Client) Remove

func (c *Client) Remove(path string) error

Remove removes a remote file

func (*Client) RemoveAll

func (c *Client) RemoveAll(path string) error

RemoveAll removes remote files

func (*Client) Rename

func (c *Client) Rename(oldpath, newpath string, overwrite bool) error

Rename moves a file from A to B

func (*Client) SetHeader

func (c *Client) SetHeader(key, value string)

SetHeader lets us set arbitrary headers for a given client

func (*Client) SetTimeout

func (c *Client) SetTimeout(timeout time.Duration)

SetTimeout exposes the ability to set a time limit for requests

func (*Client) SetTransport

func (c *Client) SetTransport(transport http.RoundTripper)

SetTransport exposes the ability to define custom transports

func (*Client) Stat

func (c *Client) Stat(path string) (os.FileInfo, error)

Stat returns the file stats for a specified path

func (*Client) Write

func (c *Client) Write(path string, data []byte, _ os.FileMode) error

Write writes data to a given path

func (*Client) WriteStream

func (c *Client) WriteStream(path string, stream io.Reader, _ os.FileMode) error

WriteStream writes a stream

type DigestAuth

type DigestAuth struct {
	// contains filtered or unexported fields
}

DigestAuth structure holds our credentials

func (*DigestAuth) Authorize

func (d *DigestAuth) Authorize(c *Client, method string, path string)

Authorize the current request

func (*DigestAuth) Pass

func (d *DigestAuth) Pass() string

Pass holds the DigestAuth password

func (*DigestAuth) Type

func (d *DigestAuth) Type() string

Type identifies the DigestAuthenticator

func (*DigestAuth) User

func (d *DigestAuth) User() string

User holds the DigestAuth username

type File

type File struct {
	// contains filtered or unexported fields
}

File is our structure for a given file

func (File) ContentType

func (f File) ContentType() string

ContentType returns the content type of a file

func (File) ETag

func (f File) ETag() string

ETag returns the ETag of a file

func (File) IsDir

func (f File) IsDir() bool

IsDir let us see if a given file is a directory or not

func (File) ModTime

func (f File) ModTime() time.Time

ModTime returns the modified time of a file

func (File) Mode

func (f File) Mode() os.FileMode

Mode will return the mode of a given file

func (File) Name

func (f File) Name() string

Name returns the name of a file

func (File) Size

func (f File) Size() int64

Size returns the size of a file

func (File) String

func (f File) String() string

String lets us see file information

func (File) Sys

func (f File) Sys() interface{}

Sys ????

type NoAuth

type NoAuth struct {
	// contains filtered or unexported fields
}

NoAuth structure holds our credentials

func (*NoAuth) Authorize

func (n *NoAuth) Authorize(c *Client, method string, path string)

Authorize the current request

func (*NoAuth) Pass

func (n *NoAuth) Pass() string

Pass returns the current password

func (*NoAuth) Type

func (n *NoAuth) Type() string

Type identifies the authenticator

func (*NoAuth) User

func (n *NoAuth) User() string

User returns the current user

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL