2014-10-23 10:39:55 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
d "gowebdav"
|
|
|
|
"flag"
|
|
|
|
"os"
|
|
|
|
"fmt"
|
|
|
|
)
|
|
|
|
|
|
|
|
func Fail(err interface{}) {
|
|
|
|
if err != nil {
|
|
|
|
fmt.Println(err)
|
|
|
|
} else {
|
|
|
|
fmt.Println("Usage: client FLAGS ARGS")
|
|
|
|
fmt.Println("Flags:")
|
|
|
|
flag.PrintDefaults()
|
|
|
|
}
|
|
|
|
os.Exit(-1)
|
|
|
|
}
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
root := flag.String("root", "URL", "WebDAV Endpoint")
|
|
|
|
usr := flag.String("user", "", "user")
|
|
|
|
pw := flag.String("pw", "", "password")
|
2014-10-23 14:10:31 +02:00
|
|
|
m := flag.String("X", "GET", "Method: LIST aka PROPFIND, GET, DELETE")
|
2014-10-23 10:39:55 +02:00
|
|
|
flag.Parse()
|
|
|
|
|
|
|
|
if *root == "URL" {
|
|
|
|
Fail(nil)
|
|
|
|
}
|
|
|
|
|
|
|
|
c := d.NewClient(*root, *usr, *pw)
|
|
|
|
if err := c.Connect(); err != nil {
|
|
|
|
Fail(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(flag.Args()) > 0 {
|
|
|
|
path := flag.Args()[0]
|
|
|
|
switch *m {
|
|
|
|
case "LIST", "PROPFIND":
|
2014-10-23 13:15:02 +02:00
|
|
|
if files, err := c.ReadDir(path); err == nil {
|
2014-10-23 14:26:08 +02:00
|
|
|
fmt.Println(fmt.Sprintf("Resources: %d - %s", len(files), path))
|
2014-10-23 13:15:02 +02:00
|
|
|
for _, f := range files {
|
|
|
|
fmt.Println(f)
|
2014-10-23 10:39:55 +02:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
fmt.Println(err)
|
|
|
|
}
|
2014-10-23 14:10:31 +02:00
|
|
|
|
2014-10-23 10:39:55 +02:00
|
|
|
case "GET": c.Read(path)
|
2014-10-23 14:10:31 +02:00
|
|
|
|
|
|
|
case "DELETE", "RM":
|
|
|
|
if err := c.Remove(path); err != nil {
|
|
|
|
fmt.Println(err)
|
|
|
|
}
|
|
|
|
|
2014-10-23 10:39:55 +02:00
|
|
|
default: Fail(nil)
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
Fail(nil)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|