-
Notifications
You must be signed in to change notification settings - Fork 0
/
ftpdav.go
58 lines (48 loc) · 1007 Bytes
/
ftpdav.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package main
import (
"encoding/json"
"flag"
"log"
"os"
"github.com/evgeni/ftpdav/driver/webdav"
"goftp.io/server/v2"
)
var (
cfgPath string
)
type Configuration struct {
URL string
User string
Password string
}
func main() {
flag.StringVar(&cfgPath, "config", "config.json", "config file path")
flag.Parse()
file, _ := os.Open(cfgPath)
defer file.Close()
decoder := json.NewDecoder(file)
configuration := Configuration{}
err := decoder.Decode(&configuration)
if err != nil {
log.Fatal(err)
}
driver, err := webdav.NewDriver(configuration.URL, configuration.User, configuration.Password, true)
if err != nil {
log.Fatal(err)
}
s, err := server.NewServer(&server.Options{
Driver: driver,
Auth: &server.SimpleAuth{
Name: "admin",
Password: "admin",
},
Perm: server.NewSimplePerm("root", "root"),
RateLimit: 1000000, // 1MB/s limit
})
if err != nil {
log.Fatal(err)
}
if err := s.ListenAndServe(); err != nil {
log.Fatal(err)
}
}