Chris Lu 4 years ago
parent
commit
f0455dee68
  1. 61
      weed/ftpd/ftp_fs.go
  2. 13
      weed/ftpd/ftp_server.go

61
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 {
}

13
weed/ftpd/ftp_server.go

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