sftp

package
v2.0.17 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 15, 2024 License: AGPL-3.0 Imports: 7 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrMissingConnectionHandlerFunction ...
	ErrMissingConnectionHandlerFunction = errors.New("new connection handler is not defined")
	// ErrMissingSSHConfig ...
	ErrMissingSSHConfig = errors.New("ssh Config is not defined")
	// ErrMissingLoggerInterface ...
	ErrMissingLoggerInterface = errors.New("logger interface is not defined")
	// ErrInvalidPort ...
	ErrInvalidPort = errors.New("port must not be 0 or bigger then 65535")
)

Functions

This section is empty.

Types

type LogType

type LogType string

LogType defined various types of logs and errors that can happen within the SFTP implementation

const (
	// ServerStarted is logged when the SFTP server is first launched.
	ServerStarted LogType = "server-started"
	// ChannelNotSession is logged when the SFTP receives a request for a new channel which is NOT of type 'session'.
	ChannelNotSession LogType = "channel-not-session"
	// AcceptNetworkError is logged when there is an error accepting network connections within the listener.
	AcceptNetworkError LogType = "accept-network-error"
	// SSHKeyExchangeError is logged when there is an error performing a key exchange between the SFTP client and server.
	SSHKeyExchangeError LogType = "ssh-key-exchange-error"
	// AcceptChannelError is logged when there is an error while trying to accept the new request channel.
	AcceptChannelError LogType = "accept-channel-error"
)

type Logger

type Logger interface {
	Info(tag LogType, msg string)
	Error(tag LogType, err error)
}

Logger implements a basic logging interface for the SFTP server.

type Options

type Options struct {
	Port      int
	PublicIP  string
	Logger    Logger
	SSHConfig *ssh.ServerConfig
	// ConnectionKeepAlive controls how long the connection keep-alive duration is set to.
	ConnectionKeepAlive time.Duration
	// SSHHandshakeDeadline controls the time.Duration which ssh session
	// have to complete their handshake. This option is not a part of the
	// ssh.ServerConfig so we had to implement it separately.
	SSHHandshakeDeadline time.Duration
	// BeforeHandle will be executed before `HandleSFTPSession` and before
	// error checking happens during the socket listener.Accept().
	//
	// if acceptConn is true the connection will be accepted, if not
	// the .Close() method is called and the connection dropped.
	BeforeHandle func(conn net.Conn, err error) (acceptConn bool)
	// HandleSFTPSession is executed when a new SFTP session is requested.
	HandleSFTPSession func(channel ssh.Channel, sconn *ssh.ServerConn)
}

Options defines required configurations used when calling NewServer().

type Server

type Server struct {
	// contains filtered or unexported fields
}

Server implements a composable SFTP Server.

func NewServer

func NewServer(options *Options) (sftpServer *Server, err error)

NewServer composes a new Server{} object from the options given.

It is recommended to use (2*time.Minute) as the SSHHandshakeDeadline. 2 minutes is the default deadline for OpenSSH servers/clients.

func (*Server) Listen

func (s *Server) Listen() (err error)

Listen starts the SFTP server

func (*Server) ShutDown

func (s *Server) ShutDown() (err error)

ShutDown calls the cancel context and shuts down the SFTP server.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL