ftptest

package
v0.9.1 Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2026 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Overview

Package ftptest is a small FTP server for tests. It speaks enough of the protocol for the client library: login, features, passive mode, list, retrieve, store, delete, size and time. It does not do active mode, REST, APPE, rename, MKD, RMD, permissions, quotas, ASCII mode or bandwidth accounting beyond the SlowData knob.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Users                  map[string]string
	Files                  map[string][]byte
	AnnounceHost           string
	NoMLST                 bool
	DOSList                bool
	RequireTLSSessionReuse bool
	NoSIZE                 bool
	CorruptDownloads       bool
}

Config is the server's files, users and fault knobs. Apply replaces the parts that are set. A nil map leaves that part as it was.

type Server

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

Server is one FTP server on 127.0.0.1.

func Start

func Start(t *testing.T) *Server

Start listens for plain FTP.

func StartImplicitTLS

func StartImplicitTLS(t *testing.T) *Server

StartImplicitTLS listens with TLS from the first byte.

func StartTLS

func StartTLS(t *testing.T) *Server

StartTLS listens for plain FTP and allows AUTH TLS.

func StartTLSConfig added in v0.8.0

func StartTLSConfig(t *testing.T, cfg *tls.Config) *Server

StartTLSConfig is StartTLS with the given server config, including a client certificate check when the config asks for one.

func (*Server) Addr

func (s *Server) Addr() string

Addr is host:port.

func (*Server) Apply

func (s *Server) Apply(cfg Config)

Apply changes users, files and knobs. A nil Users or Files map is left unchanged. AnnounceHost, when non-empty, replaces the PASV address.

func (*Server) ClearFaults

func (s *Server) ClearFaults()

ClearFaults removes stall, drop and truncate knobs.

func (*Server) Close

func (s *Server) Close()

Close stops the listener and the open connections.

func (*Server) Commands

func (s *Server) Commands() []string

Commands is the log of control commands. A password is stored as PASS ****.

func (*Server) ConnCount

func (s *Server) ConnCount() int

ConnCount is how many control connections were accepted.

func (*Server) DataConnCount

func (s *Server) DataConnCount() int

DataConnCount is how many data connections were accepted.

func (*Server) DataTLS added in v0.9.0

func (s *Server) DataTLS(cfg *tls.Config)

DataTLS makes data connections present this certificate instead of the control connection's certificate.

func (*Server) Delay

func (s *Server) Delay(d time.Duration)

Delay waits before every reply.

func (*Server) DropOn

func (s *Server) DropOn(cmd string)

DropOn closes the control connection when cmd is read.

func (*Server) File

func (s *Server) File(path string) ([]byte, bool)

File returns one stored file.

func (*Server) Files

func (s *Server) Files() map[string][]byte

Files returns a copy of the stored files.

func (*Server) Generate

func (s *Server) Generate(path string, n int64)

Generate makes RETR of path stream n zero bytes without storing them.

func (*Server) IdleTimeout

func (s *Server) IdleTimeout(d time.Duration)

IdleTimeout closes a control connection that is quiet for d, with 421.

func (*Server) MaxConnections

func (s *Server) MaxConnections(n int)

MaxConnections makes the n+1th control connection receive 421.

func (*Server) OpenConns

func (s *Server) OpenConns() int

OpenConns is how many control connections are open now.

func (*Server) RefuseConnections

func (s *Server) RefuseConnections(v bool)

RefuseConnections closes new control connections at once.

func (*Server) ReplyOn

func (s *Server) ReplyOn(cmd string, code int, text string)

ReplyOn answers cmd with a fixed code and text.

func (*Server) SlowData

func (s *Server) SlowData(bytesPerSecond int)

SlowData limits a data transfer to about bytesPerSecond.

func (*Server) StallDataAfter

func (s *Server) StallDataAfter(n int)

StallDataAfter stops a transfer after n bytes and waits.

func (*Server) StallOn

func (s *Server) StallOn(cmd string)

StallOn makes the server read cmd and then never answer.

func (*Server) TruncateDataAfter

func (s *Server) TruncateDataAfter(n int)

TruncateDataAfter closes the data connection after n bytes and replies 426.

func (*Server) URL

func (s *Server) URL() string

URL is the ftp:// or ftps:// address of the server.

Jump to

Keyboard shortcuts

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