server: github.com/goftp/server Index | Files | Directories

package server

import "github.com/goftp/server"

Index

Package Files

auth.go cmd.go conn.go doc.go driver.go fileinfo.go listformatter.go logger.go perm.go server.go socket.go

Variables

var ErrServerClosed = errors.New("ftp: Server closed")

ErrServerClosed is returned by ListenAndServe() or Serve() when a shutdown was requested.

func Version Uses

func Version() string

Version returns the library version

type Auth Uses

type Auth interface {
    CheckPasswd(string, string) (bool, error)
}

Auth is an interface to auth your ftp user login.

type Command Uses

type Command interface {
    IsExtend() bool
    RequireParam() bool
    RequireAuth() bool
    Execute(*Conn, string)
}

type Conn Uses

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

func (*Conn) Close Uses

func (conn *Conn) Close()

Close will manually close this connection, even if the client isn't ready.

func (*Conn) IsLogin Uses

func (conn *Conn) IsLogin() bool

func (*Conn) LoginUser Uses

func (conn *Conn) LoginUser() string

func (*Conn) PassivePort Uses

func (conn *Conn) PassivePort() int

func (*Conn) PublicIp Uses

func (conn *Conn) PublicIp() string

func (*Conn) Serve Uses

func (conn *Conn) Serve()

Serve starts an endless loop that reads FTP commands from the client and responds appropriately. terminated is a channel that will receive a true message when the connection closes. This loop will be running inside a goroutine, so use this channel to be notified when the connection can be cleaned up.

type DataSocket Uses

type DataSocket interface {
    Host() string

    Port() int

    // the standard io.Reader interface
    Read(p []byte) (n int, err error)

    // the standard io.ReaderFrom interface
    ReadFrom(r io.Reader) (int64, error)

    // the standard io.Writer interface
    Write(p []byte) (n int, err error)

    // the standard io.Closer interface
    Close() error
}

DataSocket describes a data socket is used to send non-control data between the client and server.

type DiscardLogger Uses

type DiscardLogger struct{}

Silent logger, produces no output

func (*DiscardLogger) Print Uses

func (logger *DiscardLogger) Print(sessionId string, message interface{})

func (*DiscardLogger) PrintCommand Uses

func (logger *DiscardLogger) PrintCommand(sessionId string, command string, params string)

func (*DiscardLogger) PrintResponse Uses

func (logger *DiscardLogger) PrintResponse(sessionId string, code int, message string)

func (*DiscardLogger) Printf Uses

func (logger *DiscardLogger) Printf(sessionId string, format string, v ...interface{})

type Driver Uses

type Driver interface {
    // Init init
    Init(*Conn)

    // params  - a file path
    // returns - a time indicating when the requested path was last modified
    //         - an error if the file doesn't exist or the user lacks
    //           permissions
    Stat(string) (FileInfo, error)

    // params  - path
    // returns - true if the current user is permitted to change to the
    //           requested path
    ChangeDir(string) error

    // params  - path, function on file or subdir found
    // returns - error
    //           path
    ListDir(string, func(FileInfo) error) error

    // params  - path
    // returns - nil if the directory was deleted or any error encountered
    DeleteDir(string) error

    // params  - path
    // returns - nil if the file was deleted or any error encountered
    DeleteFile(string) error

    // params  - from_path, to_path
    // returns - nil if the file was renamed or any error encountered
    Rename(string, string) error

    // params  - path
    // returns - nil if the new directory was created or any error encountered
    MakeDir(string) error

    // params  - path
    // returns - a string containing the file data to send to the client
    GetFile(string, int64) (int64, io.ReadCloser, error)

    // params  - destination path, an io.Reader containing the file data
    // returns - the number of bytes writen and the first error encountered while writing, if any.
    PutFile(string, io.Reader, bool) (int64, error)
}

Driver is an interface that you will create an implementation that speaks to your chosen persistence layer. graval will create a new instance of your driver for each client that connects and delegate to it as required.

type DriverFactory Uses

type DriverFactory interface {
    NewDriver() (Driver, error)
}

DriverFactory is a driver factory to create driver. For each client that connects to the server, a new FTPDriver is required. Create an implementation if this interface and provide it to FTPServer.

type FileInfo Uses

type FileInfo interface {
    os.FileInfo

    Owner() string
    Group() string
}

type Logger Uses

type Logger interface {
    Print(sessionId string, message interface{})
    Printf(sessionId string, format string, v ...interface{})
    PrintCommand(sessionId string, command string, params string)
    PrintResponse(sessionId string, code int, message string)
}

type Perm Uses

type Perm interface {
    GetOwner(string) (string, error)
    GetGroup(string) (string, error)
    GetMode(string) (os.FileMode, error)

    ChOwner(string, string) error
    ChGroup(string, string) error
    ChMode(string, os.FileMode) error
}

type Server Uses

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

Server is the root of your FTP application. You should instantiate one of these and call ListenAndServe() to start accepting client connections.

Always use the NewServer() method to create a new Server.

func NewServer Uses

func NewServer(opts *ServerOpts) *Server

NewServer initialises a new FTP server. Configuration options are provided via an instance of ServerOpts. Calling this function in your code will probably look something like this:

factory := &MyDriverFactory{}
server  := server.NewServer(&server.ServerOpts{ Factory: factory })

or:

factory := &MyDriverFactory{}
opts    := &server.ServerOpts{
  Factory: factory,
  Port: 2000,
  Hostname: "127.0.0.1",
}
server  := server.NewServer(opts)

func (*Server) ListenAndServe Uses

func (server *Server) ListenAndServe() error

ListenAndServe asks a new Server to begin accepting client connections. It accepts no arguments - all configuration is provided via the NewServer function.

If the server fails to start for any reason, an error will be returned. Common errors are trying to bind to a privileged port or something else is already listening on the same port.

func (*Server) Serve Uses

func (server *Server) Serve(l net.Listener) error

Serve accepts connections on a given net.Listener and handles each request in a new goroutine.

func (*Server) Shutdown Uses

func (server *Server) Shutdown() error

Shutdown will gracefully stop a server. Already connected clients will retain their connections

type ServerOpts Uses

type ServerOpts struct {
    // The factory that will be used to create a new FTPDriver instance for
    // each client connection. This is a mandatory option.
    Factory DriverFactory

    Auth Auth

    // Server Name, Default is Go Ftp Server
    Name string

    // The hostname that the FTP server should listen on. Optional, defaults to
    // "::", which means all hostnames on ipv4 and ipv6.
    Hostname string

    // Public IP of the server
    PublicIp string

    // Passive ports
    PassivePorts string

    // The port that the FTP should listen on. Optional, defaults to 3000. In
    // a production environment you will probably want to change this to 21.
    Port int

    // use tls, default is false
    TLS bool

    // if tls used, cert file is required
    CertFile string

    // if tls used, key file is required
    KeyFile string

    // If ture TLS is used in RFC4217 mode
    ExplicitFTPS bool

    WelcomeMessage string

    // A logger implementation, if nil the StdLogger is used
    Logger Logger
}

ServerOpts contains parameters for server.NewServer()

type SimpleAuth Uses

type SimpleAuth struct {
    Name     string
    Password string
}

SimpleAuth implements Auth interface to provide a memory user login auth

func (*SimpleAuth) CheckPasswd Uses

func (a *SimpleAuth) CheckPasswd(name, pass string) (bool, error)

CheckPasswd will check user's password

type SimplePerm Uses

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

func NewSimplePerm Uses

func NewSimplePerm(owner, group string) *SimplePerm

func (*SimplePerm) ChGroup Uses

func (s *SimplePerm) ChGroup(string, string) error

func (*SimplePerm) ChMode Uses

func (s *SimplePerm) ChMode(string, os.FileMode) error

func (*SimplePerm) ChOwner Uses

func (s *SimplePerm) ChOwner(string, string) error

func (*SimplePerm) GetGroup Uses

func (s *SimplePerm) GetGroup(string) (string, error)

func (*SimplePerm) GetMode Uses

func (s *SimplePerm) GetMode(string) (os.FileMode, error)

func (*SimplePerm) GetOwner Uses

func (s *SimplePerm) GetOwner(string) (string, error)

type StdLogger Uses

type StdLogger struct{}

Use an instance of this to log in a standard format

func (*StdLogger) Print Uses

func (logger *StdLogger) Print(sessionId string, message interface{})

func (*StdLogger) PrintCommand Uses

func (logger *StdLogger) PrintCommand(sessionId string, command string, params string)

func (*StdLogger) PrintResponse Uses

func (logger *StdLogger) PrintResponse(sessionId string, code int, message string)

func (*StdLogger) Printf Uses

func (logger *StdLogger) Printf(sessionId string, format string, v ...interface{})

Directories

PathSynopsis
exampleftpdThis is a very simple ftpd server using this library as an example and as something to run tests against.

Package server imports 23 packages (graph) and is imported by 21 packages. Updated 2019-07-12. Refresh now. Tools for package owners.