server

package
v0.0.0-...-ba2ee57 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2017 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package server provides all the tools to build your own FTP server: The core library and the driver.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ClientContext

type ClientContext interface {
	// Path provides the path of the current connection
	Path() string

	// SetDebug activates the debugging of this connection commands
	SetDebug(debug bool)

	// Debug returns the current debugging status of this connection commands
	Debug() bool

	// Client's ID on the server
	ID() uint32

	// Client's address
	RemoteAddr() net.Addr
}

ClientContext is implemented on the server side to provide some access to few data around the client

type ClientHandlingDriver

type ClientHandlingDriver interface {
	// ChangeDirectory changes the current working directory
	ChangeDirectory(cc ClientContext, directory string) error

	// MakeDirectory creates a directory
	MakeDirectory(cc ClientContext, directory string) error

	// ListFiles lists the files of a directory
	ListFiles(cc ClientContext) ([]os.FileInfo, error)

	// OpenFile opens a file in 3 possible modes: read, write, appending write (use appropriate flags)
	OpenFile(cc ClientContext, path string, flag int) (FileStream, error)

	// DeleteFile deletes a file or a directory
	DeleteFile(cc ClientContext, path string) error

	// GetFileInfo gets some info around a file or a directory
	GetFileInfo(cc ClientContext, path string) (os.FileInfo, error)

	// RenameFile renames a file or a directory
	RenameFile(cc ClientContext, from, to string) error

	// CanAllocate gives the approval to allocate some data
	CanAllocate(cc ClientContext, size int) (bool, error)

	// ChmodFile changes the attributes of the file
	ChmodFile(cc ClientContext, path string, mode os.FileMode) error
}

ClientHandlingDriver handles the file system access logic

type CommandDescription

type CommandDescription struct {
	Open bool                 // Open to clients without auth
	Fn   func(*clientHandler) // Function to handle it
}

CommandDescription defines which function should be used and if it should be open to anyone or only logged in users

type FileStream

type FileStream interface {
	io.Writer
	io.Reader
	io.Closer
	io.Seeker
}

FileStream is a read or write closeable stream

type FtpServer

type FtpServer struct {
	Logger log.Logger // Go-Kit logger
	// contains filtered or unexported fields
}

FtpServer is where everything is stored We want to keep it as simple as possible

func NewFtpServer

func NewFtpServer(driver MainDriver) *FtpServer

NewFtpServer creates a new FtpServer instance

func (*FtpServer) Addr

func (server *FtpServer) Addr() string

Addr shows the listening address

func (*FtpServer) Listen

func (server *FtpServer) Listen() error

Listen starts the listening It's not a blocking call

func (*FtpServer) ListenAndServe

func (server *FtpServer) ListenAndServe() error

ListenAndServe simply chains the Listen and Serve method calls

func (*FtpServer) Serve

func (server *FtpServer) Serve()

Serve accepts and process any new client coming

func (*FtpServer) Stop

func (server *FtpServer) Stop()

Stop closes the listener

type MainDriver

type MainDriver interface {
	// GetSettings returns some general settings around the server setup
	GetSettings() (*Settings, error)

	// WelcomeUser is called to send the very first welcome message
	WelcomeUser(cc ClientContext) (string, error)

	// UserLeft is called when the user disconnects, even if he never authenticated
	UserLeft(cc ClientContext)

	// AuthUser authenticates the user and selects an handling driver
	AuthUser(cc ClientContext, user, pass string) (ClientHandlingDriver, error)

	// GetTLSConfig returns a TLS Certificate to use
	// The certificate could frequently change if we use something like "let's encrypt"
	GetTLSConfig() (*tls.Config, error)
}

MainDriver handles the authentication and ClientHandlingDriver selection

type PortRange

type PortRange struct {
	Start int // Range start
	End   int // Range end
}

PortRange is a range of ports

type Settings

type Settings struct {
	ListenAddr                string     // Listening address
	PublicHost                string     // Public IP to expose (only an IP address is accepted at this stage)
	DataPortRange             *PortRange // Port Range for data connections. Random one will be used if not specified
	DisableMLSD               bool       // Disable MLSD support
	NonStandardActiveDataPort bool       // Allow to use a non-standard active data port
}

Settings defines all the server settings

Jump to

Keyboard shortcuts

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