This commit is contained in:
Chris Lu 2020-12-26 23:46:20 -08:00
parent aa020ee7e7
commit f0455dee68
2 changed files with 72 additions and 2 deletions

61
weed/ftpd/ftp_fs.go Normal file
View file

@ -0,0 +1,61 @@
package ftpd
import (
"github.com/chrislusf/seaweedfs/weed/util"
"github.com/spf13/afero"
"net"
"os"
"time"
)
type FtpFileSystem struct {
option *FtpServerOption
ftpListener net.Listener
}
var (
_ = afero.Fs(&FtpFileSystem{})
)
// NewServer returns a new FTP server driver
func NewFtpFileSystem(option *FtpServerOption) (*FtpFileSystem, error) {
return &FtpFileSystem{
option: option,
}, nil
}
func (fs *FtpFileSystem) Create(name string) (afero.File, error) {
}
func (fs *FtpFileSystem) Mkdir(name string, perm os.FileMode) error {
}
func (fs *FtpFileSystem) MkdirAll(path string, perm os.FileMode) error {
}
func (fs *FtpFileSystem) Open(name string) (afero.File, error) {
}
func (fs *FtpFileSystem) OpenFile(name string, flag int, perm os.FileMode) (afero.File, error) {
}
func (fs *FtpFileSystem) Remove(name string) error {
}
func (fs *FtpFileSystem) RemoveAll(path string) error {
}
func (fs *FtpFileSystem) Rename(oldname, newname string) error {
}
func (fs *FtpFileSystem) Stat(name string) (os.FileInfo, error) {
}
func (fs *FtpFileSystem) Name() string {
return "SeaweedFS FTP Server " + util.Version()
}
func (fs *FtpFileSystem) Chmod(name string, mode os.FileMode) error {
}
func (fs *FtpFileSystem) Chtimes(name string, atime time.Time, mtime time.Time) error {
}

View file

@ -4,6 +4,7 @@ import (
"crypto/tls"
"errors"
"fmt"
"github.com/spf13/afero"
"net"
ftpserver "github.com/fclairamb/ftpserverlib"
@ -25,16 +26,18 @@ type FtpServerOption struct {
type SftpServer struct {
option *FtpServerOption
ftpListener net.Listener
fs *FtpFileSystem
}
var _ = ftpserver.MainDriver(&SftpServer{})
// NewServer returns a new FTP server driver
func NewFtpServer(ftpListener net.Listener, option *FtpServerOption) (*SftpServer, error) {
var err error
fs, err := NewFtpFileSystem(option)
server := &SftpServer{
option: option,
ftpListener: ftpListener,
fs: fs,
}
return server, err
}
@ -71,7 +74,9 @@ func (s *SftpServer) ClientDisconnected(cc ftpserver.ClientContext) {
// AuthUser authenticates the user and selects an handling driver
func (s *SftpServer) AuthUser(cc ftpserver.ClientContext, username, password string) (ftpserver.ClientDriver, error) {
return nil, nil
return &ClientDriver{
Fs: s.fs,
}, nil
}
// GetTLSConfig returns a TLS Certificate to use
@ -79,3 +84,7 @@ func (s *SftpServer) AuthUser(cc ftpserver.ClientContext, username, password str
func (s *SftpServer) GetTLSConfig() (*tls.Config, error) {
return nil, errors.New("no TLS certificate configured")
}
type ClientDriver struct {
afero.Fs
}