-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexampleftpd.go
49 lines (42 loc) · 1.26 KB
/
exampleftpd.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
// Copyright 2018 The goftp Authors. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
// This is a very simple ftpd server using this library as an example
// and as something to run tests against.
package main
import (
"flag"
"log"
filedriver "gitea.com/goftp/file-driver"
"goftp.io/server"
)
func main() {
var (
root = flag.String("root", "", "Root directory to serve")
user = flag.String("user", "admin", "Username for login")
pass = flag.String("pass", "123456", "Password for login")
port = flag.Int("port", 2121, "Port")
host = flag.String("host", "localhost", "Host")
)
flag.Parse()
if *root == "" {
log.Fatalf("Please set a root to serve with -root")
}
factory := &filedriver.FileDriverFactory{
RootPath: *root,
Perm: server.NewSimplePerm("user", "group"),
}
opts := &server.ServerOpts{
Factory: factory,
Port: *port,
Hostname: *host,
Auth: &server.SimpleAuth{Name: *user, Password: *pass},
}
log.Printf("Starting ftp server on %v:%v", opts.Hostname, opts.Port)
log.Printf("Username %v, Password %v", *user, *pass)
server := server.NewServer(opts)
err := server.ListenAndServe()
if err != nil {
log.Fatal("Error starting server:", err)
}
}