server

package
v0.0.0-...-d9f74f5 Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2018 License: MIT Imports: 13 Imported by: 2

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

	// User returns the authenticated user of the current connection
	User() string
}

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)

	// NotifyWrite is called whenever a file is written
	NotifyWrite(cc ClientContext, path string) error
}

ClientHandlingDriver handles the file system access logic

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 {
	Settings  *Settings    // General settings
	Listener  net.Listener // Listener used to receive files
	StartTime time.Time    // Time when the server was started
	// contains filtered or unexported fields
}

func NewFtpServer

func NewFtpServer(driver ServerDriver) *FtpServer

func (*FtpServer) ListenAndServe

func (server *FtpServer) ListenAndServe() error

func (*FtpServer) NewClientHandler

func (server *FtpServer) NewClientHandler(connection net.Conn) *clientHandler

func (*FtpServer) SetDebugStream

func (server *FtpServer) SetDebugStream(stream io.Writer)

func (*FtpServer) Stop

func (server *FtpServer) Stop() error

type ServerDriver

type ServerDriver interface {
	// Load some general settings around the server setup
	GetSettings() *Settings

	// 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)

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

ServerDriver handles the authentication and ClientHandlingDriver selection

type Settings

type Settings struct {
	ListenHost     string // Host to receive connections on
	ListenPort     int    // Port to listen on
	PublicHost     string // Public IP to expose (only an IP address is accepted at this stage)
	MaxConnections int    // Max number of connections to accept
}

Settings define all the server settings

Jump to

Keyboard shortcuts

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