From f0455dee683e831487c345a575b7894c0e2bf61a Mon Sep 17 00:00:00 2001 From: Chris Lu Date: Sat, 26 Dec 2020 23:46:20 -0800 Subject: [PATCH] WIP --- weed/ftpd/ftp_fs.go | 61 +++++++++++++++++++++++++++++++++++++++++ weed/ftpd/ftp_server.go | 13 +++++++-- 2 files changed, 72 insertions(+), 2 deletions(-) create mode 100644 weed/ftpd/ftp_fs.go diff --git a/weed/ftpd/ftp_fs.go b/weed/ftpd/ftp_fs.go new file mode 100644 index 000000000..58ed60d17 --- /dev/null +++ b/weed/ftpd/ftp_fs.go @@ -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 { + +} diff --git a/weed/ftpd/ftp_server.go b/weed/ftpd/ftp_server.go index 4a0dca2c3..633a0371c 100644 --- a/weed/ftpd/ftp_server.go +++ b/weed/ftpd/ftp_server.go @@ -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 +}