Documentation ¶
Overview ¶
Package server provides all the tools to build your own FTP server: The core library and the driver.
Index ¶
Constants ¶
const ( // 100 Series - The requested action is being initiated, expect another reply before // proceeding with a new command. StatusFileStatusOK = 150 // RFC 959, 4.2.1 // 200 Series - The requested action has been successfully completed. StatusOK = 200 // RFC 959, 4.2.1 StatusNotImplemented = 202 // RFC 959, 4.2.1 StatusSystemStatus = 211 // RFC 959, 4.2.1 StatusDirectoryStatus = 212 // RFC 959, 4.2.1 StatusFileStatus = 213 // RFC 959, 4.2.1 StatusHelpMessage = 214 // RFC 959, 4.2.1 StatusSystemType = 215 // RFC 959, 4.2.1 StatusServiceReady = 220 // RFC 959, 4.2.1 StatusClosingControlConn = 221 // RFC 959, 4.2.1 StatusClosingDataConn = 226 // RFC 959, 4.2.1 StatusEnteringPASV = 227 // RFC 959, 4.2.1 StatusEnteringEPSV = 229 // RFC 2428, 3 StatusUserLoggedIn = 230 // RFC 959, 4.2.1 StatusAuthAccepted = 234 // RFC 2228, 3 StatusFileOK = 250 // RFC 959, 4.2.1 StatusPathCreated = 257 // RFC 959, 4.2.1 // 300 Series - The command has been accepted, but the requested action is on hold, // pending receipt of further information. StatusUserOK = 331 // RFC 959, 4.2.1 StatusFileActionPending = 350 // RFC 959, 4.2.1 // 400 Series - The command was not accepted and the requested action did not take place, // but the error condition is temporary and the action may be requested again. StatusServiceNotAvailable = 421 // RFC 959, 4.2.1 StatusFileActionNotTaken = 450 // RFC 959, 4.2.1 // 500 Series - Syntax error, command unrecognized and the requested action did not take // place. This may include errors such as command line too long. StatusSyntaxErrorNotRecognised = 500 // RFC 959, 4.2.1 StatusSyntaxErrorParameters = 501 // RFC 959, 4.2.1 StatusCommandNotImplemented = 502 // RFC 959, 4.2.1 StatusNotLoggedIn = 530 // RFC 959, 4.2.1 StatusActionNotTaken = 550 // RFC 959, 4.2.1 )
Status codes as documented by: https://tools.ietf.org/html/rfc959 https://tools.ietf.org/html/rfc2428 https://tools.ietf.org/html/rfc2228
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 // Servers's address LocalAddr() 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) error // 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 ¶
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 PublicIPResolver ¶
type PublicIPResolver func(ClientContext) (string, error)
PublicIPResolver takes a ClientContext for a connection and returns the public IP to use in the response to the PASV command, or an error if a public IP cannot be determined.
type Settings ¶
type Settings struct { Listener net.Listener // Allow providing an already initialized listener. Mutually exclusive with ListenAddr ListenAddr string // Listening address PublicHost string // Public IP to expose (only an IP address is accepted at this stage) PublicIPResolver PublicIPResolver // Optional function that can perform a public ip lookup for the given CientContext. DataPortRange *PortRange // Port Range for data connections. Random one will be used if not specified DisableMLSD bool // Disable MLSD support DisableMLST bool // Disable MLST support NonStandardActiveDataPort bool // Allow to use a non-standard active data port IdleTimeout int // Maximum inactivity time before disconnecting (#58) }
Settings defines all the server settings