mirror of
https://github.com/chrislusf/seaweedfs
synced 2025-06-29 16:22:46 +02:00
* Add SFTP Server Support Signed-off-by: Mohamed Sekour <mohamed.sekour@exfo.com> * fix s3 tests and helm lint Signed-off-by: Mohamed Sekour <mohamed.sekour@exfo.com> * increase helm chart version * adjust version --------- Signed-off-by: Mohamed Sekour <mohamed.sekour@exfo.com> Co-authored-by: chrislu <chris.lu@gmail.com>
59 lines
1.6 KiB
Go
59 lines
1.6 KiB
Go
// sftp_server.go
|
|
package sftpd
|
|
|
|
import (
|
|
"io"
|
|
|
|
"github.com/pkg/sftp"
|
|
"github.com/seaweedfs/seaweedfs/weed/pb"
|
|
"github.com/seaweedfs/seaweedfs/weed/sftpd/auth"
|
|
"github.com/seaweedfs/seaweedfs/weed/sftpd/user"
|
|
"google.golang.org/grpc"
|
|
)
|
|
|
|
type SftpServer struct {
|
|
filerAddr pb.ServerAddress
|
|
grpcDialOption grpc.DialOption
|
|
dataCenter string
|
|
filerGroup string
|
|
user *user.User
|
|
authManager *auth.Manager
|
|
}
|
|
|
|
// NewSftpServer constructs the server.
|
|
func NewSftpServer(filerAddr pb.ServerAddress, grpcDialOption grpc.DialOption, dataCenter, filerGroup string, user *user.User) SftpServer {
|
|
// Create a file system helper for the auth manager
|
|
fsHelper := NewFileSystemHelper(filerAddr, grpcDialOption, dataCenter, filerGroup)
|
|
|
|
// Create an auth manager for permission checking
|
|
authManager := auth.NewManager(nil, fsHelper, []string{})
|
|
|
|
return SftpServer{
|
|
filerAddr: filerAddr,
|
|
grpcDialOption: grpcDialOption,
|
|
dataCenter: dataCenter,
|
|
filerGroup: filerGroup,
|
|
user: user,
|
|
authManager: authManager,
|
|
}
|
|
}
|
|
|
|
// Fileread is invoked for “get” requests.
|
|
func (fs *SftpServer) Fileread(req *sftp.Request) (io.ReaderAt, error) {
|
|
return fs.readFile(req)
|
|
}
|
|
|
|
// Filewrite is invoked for “put” requests.
|
|
func (fs *SftpServer) Filewrite(req *sftp.Request) (io.WriterAt, error) {
|
|
return fs.newFileWriter(req)
|
|
}
|
|
|
|
// Filecmd handles Remove, Rename, Mkdir, Rmdir, etc.
|
|
func (fs *SftpServer) Filecmd(req *sftp.Request) error {
|
|
return fs.dispatchCmd(req)
|
|
}
|
|
|
|
// Filelist handles directory listings.
|
|
func (fs *SftpServer) Filelist(req *sftp.Request) (sftp.ListerAt, error) {
|
|
return fs.listDir(req)
|
|
}
|