Documentation
¶
Index ¶
- Variables
- func EHostPort(addr *net.TCPAddr) string
- func HostPort(addr *net.TCPAddr) string
- func ParseEPRT(msg string) (*net.TCPAddr, error)
- func ParseEPSV(msg string) (int, error)
- func ParsePASV(msg string) (*net.TCPAddr, error)
- func ParsePORT(msg string) (*net.TCPAddr, error)
- type Authorizer
- type Client
- func (c *Client) Authorize(user, pass string) (bool, error)
- func (c *Client) Chdir(dir string) error
- func (c *Client) Close() error
- func (c *Client) Connect() error
- func (c *Client) Create(path string) (File, error)
- func (c *Client) Mkdir(path string) error
- func (c *Client) Open(path string) (File, error)
- func (c *Client) Remove(path string) error
- func (c *Client) Rename(old, new string) error
- func (c *Client) Stat(p string) (os.FileInfo, error)
- type Command
- type Conn
- func (c *Conn) Active() bool
- func (c *Conn) Addr() net.Addr
- func (c *Conn) Close() (err error)
- func (c *Conn) EHostPort() string
- func (c *Conn) Flush() error
- func (c *Conn) HostPort() string
- func (c *Conn) LocalAddr() net.Addr
- func (c *Conn) Mode(m string)
- func (c *Conn) Passive() bool
- func (c *Conn) Port() int
- func (c *Conn) Read(b []byte) (n int, err error)
- func (c *Conn) ReadLine() (line string, err error)
- func (c *Conn) RemoteAddr() net.Addr
- func (c *Conn) SetDeadline(t time.Time) error
- func (c *Conn) SetReadDeadline(t time.Time) error
- func (c *Conn) SetWriteDeadline(t time.Time) error
- func (c *Conn) Type(t string)
- func (c *Conn) Write(b []byte) (n int, err error)
- type Context
- type Dialer
- type File
- type FileHandler
- type FileSystem
- type Handler
- type Listener
- type Lister
- type LocalFileSystem
- func (f *LocalFileSystem) Create(path string) (File, error)
- func (f *LocalFileSystem) Mkdir(path string) error
- func (f *LocalFileSystem) Open(path string) (File, error)
- func (f *LocalFileSystem) Remove(path string) error
- func (f *LocalFileSystem) Rename(old, new string) error
- func (f *LocalFileSystem) Stat(path string) (os.FileInfo, error)
- type Reply
- type Server
- type Session
- func (s *Session) Active(addr net.Addr) error
- func (s *Session) Close() error
- func (s *Session) Command() (*Command, error)
- func (s *Session) Passive(nw string) error
- func (s *Session) Reply(code int, msg string, args ...interface{}) error
- func (s *Session) SetMode(m string) error
- func (s *Session) SetType(t string) error
Constants ¶
This section is empty.
Variables ¶
var DefaultGoodbye = "Goodbye."
DefaultGoodbye is the default goodbye message for closing sessions.
var DefaultGreeting = "Welcome."
DefaultGreeting is the default greeting for new connections.
var ErrInvalidSyntax = errors.New("invalid syntax")
ErrInvalidSyntax is returned by parsing functions if the input could not be parsed.
Functions ¶
Types ¶
type Authorizer ¶
type Authorizer interface { // Authorize the user. Returning an error closes the session. Authorize(user, pass string) (bool, error) }
An Authorizer can be used with a FileHandler to handle login.
type Client ¶
type Client struct { Addr string // Addr of server to connect to. Dialer Dialer // Dialer for outgoing connections. Listener Listener // Listener for incoming connections. Debug bool // Debug prints control channel traffic. // contains filtered or unexported fields }
Client for interacting with a server.
type Command ¶
type Command struct { Cmd string // Cmd is the command type. Msg string // Msg is the full message. }
A Command read from or written to a control channel.
type Conn ¶
type Conn struct {
// contains filtered or unexported fields
}
A Conn represents a data channel. This transforms data according to the transfer type and also performs buffering.
func PassiveConn ¶
PassiveConn creates a passive connection over l. This will close l once a connection has been established.
func (*Conn) Active ¶
Active returns whether this is an active connection or a passive one that has accepted a connection.
func (*Conn) Addr ¶
Addr returns the listening address if this is a passive connection. Otherwise, this returns the remote address of the active connection.
func (*Conn) Read ¶
Read implements io.Reader. If a connection has not been established, this waits for a connection.
func (*Conn) ReadLine ¶
ReadLine reads a line. If a connection has not been established, this waits for a connection.
func (*Conn) RemoteAddr ¶
RemoteAddr waits for a connection, then calls RemoteAddr on it.
func (*Conn) SetDeadline ¶
SetDeadline waits for a connection, then calls SetDeadline on it.
func (*Conn) SetReadDeadline ¶
SetReadDeadline waits for a connection, then calls SetReadDeadline on it.
func (*Conn) SetWriteDeadline ¶
SetWriteDeadline waits for a connection, then calls SetWriteDeadline on it.
type Context ¶
type Context struct { User string // User name used to authorize the session. Password string // Password used to authorize the session. Dir string // Dir is the working directory. Mode string // Mode of data transfer. Type string // Type of data channel. Data *Conn // Data channel connection. }
Context shared between clients and servers.
type File ¶
type File interface { io.Reader io.Writer io.Seeker io.Closer // Readdir has semantics like os.Readdir. Readdir(n int) ([]os.FileInfo, error) }
File is the interface returned by certain FileSystem methods.
type FileHandler ¶
type FileHandler struct { Authorizer // Authorizer for login. If nil, accept all. FileSystem // FileSystem to serve. }
A FileHandler serves from a FileSystem.
func (*FileHandler) Handle ¶
func (h *FileHandler) Handle(s *Session) error
Handle implements Handler.
type FileSystem ¶
type FileSystem interface { Create(path string) (File, error) // Create a new file. Mkdir(path string) error // Mkdir makes a new directory. Open(path string) (File, error) // Open a file or directory. Remove(path string) error // Remove a file or directory. Rename(old, new string) error // Rename a file or directory. Stat(path string) (os.FileInfo, error) // Stat a file or directory. }
FileSystem is the interface expected by a FileHandler. This type is intended to work with the os package. If errors returned by these methods match errors returned by os package functions, more informative reply codes may be chosen by a FileHandler in response to failed commands.
type Handler ¶
type Handler interface { // Handle a session. It is optional to send a greeting or reply to a QUIT. // The session is closed by the Server on return. The return value is for // composing Handlers and is ignored by the Server. Handle(*Session) error }
A Handler for a session.
type LocalFileSystem ¶
type LocalFileSystem struct {
Root string // Root of the file system, or current directory if "".
}
LocalFileSystem is a FileSystem implementation that calls os package functions.
func (*LocalFileSystem) Create ¶
func (f *LocalFileSystem) Create(path string) (File, error)
Create implements FileSystem.
func (*LocalFileSystem) Mkdir ¶
func (f *LocalFileSystem) Mkdir(path string) error
Mkdir implements FileSystem.
func (*LocalFileSystem) Open ¶
func (f *LocalFileSystem) Open(path string) (File, error)
Open implements FileSystem.
func (*LocalFileSystem) Remove ¶
func (f *LocalFileSystem) Remove(path string) error
Remove implements FileSystem.
func (*LocalFileSystem) Rename ¶
func (f *LocalFileSystem) Rename(old, new string) error
Rename implements FileSystem.
type Reply ¶
A Reply read from or written to a control channel.
func (*Reply) Intermediate ¶
Intermediate returns whether r.Code is 3xx.
func (*Reply) Preliminary ¶
Preliminary returns whether r.Code is 1xx.
type Server ¶
type Server struct { Addr string // Addr to bind the control channel to. TLS *tls.Config // TLS config enables FTPS if non-nil. Dialer Dialer // Dialer for active connections. Listener Listener // Listener for passive connections. Handler Handler // Handler for commands. Debug bool // Debug prints control channel traffic. }
A Server serves incoming connections.
func (*Server) ListenAndServe ¶
ListenAndServe listens on s.Addr and serves incoming connections. If fork is true, Serve is called on a new goroutine. Otherwise, Serve is called on this goroutine.
type Session ¶
type Session struct { Addr net.Addr // Addr of remote host. Server *Server // Server the session belongs to. Context // Context shared with the client. TLS *tls.Config // TLS config to use for data connections. // contains filtered or unexported fields }
A Session represents a single control channel session with a client.
func (*Session) Active ¶
Active establishes an active data channel connection through the associated server's dialer. This sets s.Data and closes any existing data channel.
func (*Session) Close ¶
Close the session. This will send a default goodbye reply if one has not been sent in response to a QUIT.
func (*Session) Command ¶
Command reads the next command, or returns the current command if it has already been read and has not been replied to. If the greeting has not been sent, this will send the greeting first.
func (*Session) Passive ¶
Passive creates a passive connection listening through the associated server's listener. This sets s.Data and closes any existing data channel.
func (*Session) Reply ¶
Reply sends a reply. This must be called with a non-intermediate reply code in order to allow the next command to be read. After replying to a QUIT command with a non-intermediate response code, the session is closed.