master
Bel LaPointe 2019-04-14 17:03:19 -06:00
commit 038d79b6a7
3 changed files with 62 additions and 0 deletions

4
.gitignore vendored Normal file
View File

@ -0,0 +1,4 @@
**.sw*
tmp
ftp
goftp

9
Dockerfile Normal file
View File

@ -0,0 +1,9 @@
FROM frolvlad/alpine-glibc:alpine-3.9_glibc-2.28
WORKDIR /opt
COPY ./ftp /opt/ftp
EXPOSE 42121
CMD []
ENTRYPOINT ["/opt/ftp", "-root", "/mnt", "-host", "", "-port", "42121"]

49
main.go Executable file
View File

@ -0,0 +1,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 "github.com/goftp/file-driver"
"github.com/goftp/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", "Port")
)
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)
}
}