-
go get goftp.io/server
package main
import (
"log"
"goftp.io/server/core"
"goftp.io/server/driver/file"
)
func main() {
Name := "FTP Server"
rootPath := "./static" //FTP根目录
Port := 59044 //FTP 端口
var perm = core.NewSimplePerm("test", "test")
// Server options without hostname or port
opt := &core.ServerOpts{
Name: Name,
Factory: &file.DriverFactory{
RootPath: rootPath,
Perm: perm,
},
Auth: &core.SimpleAuth{
Name: "admin", // FTP 账号
Password: "admin", // FTP 密码
},
Port: Port,
}
// start ftp server
s := core.NewServer(opt)
err := s.ListenAndServe()
if err != nil {
log.Fatal("Error starting server:", err)
}
}
参考地址:
server - A FTP server framework written by Golanghttps://gitea.com/goftp/server