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 ¶
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) ListenAndServe ¶
ListenAndServe simply chains the Listen and Serve method calls
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 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