tftp

package
v0.15.0 Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2025 License: BSD-3-Clause Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidTransferMode = errors.New("invalid transfer mode")

ErrInvalidTransferMode is returned by ValidateMode in case the provided mode string has no matching tftp.TransferMode.

Functions

func ExecuteOp

func ExecuteOp(input []string, clientcfg *ClientCfg, stdout io.Writer) (bool, error)

ExecuteOp executes a given command on input[0] with args in input[1:]. Depending on the command, clientcfg is manipulated or used to create a new client for get and put command.

func RunInteractive

func RunInteractive(f Flags, ipPort []string, stdin io.Reader, stdout io.Writer) error

RunInteractive starts the internal interactive command loop, where the user provides input to control the application.

func ValidateMode

func ValidateMode(mode string) (tftp.TransferMode, error)

ValidateMode takes a the modes string 'ascii' or 'binary' and returns the valid tftp.TransferMode or error.

Types

type Client

type Client struct {
	*tftp.Client
}

Client implements the ClientIf and uses the tftp.Client as member to interact with the real library.

func NewClient

func NewClient(ccfg *ClientCfg) (*Client, error)

NewClient sets up a new tftp.Client according to the given ClientCfg struct.

func (*Client) Get

func (c *Client) Get(url string) (Response, error)

Get provides the Get method of tftp.Client.

func (*Client) Put

func (c *Client) Put(url string, r io.Reader, size int64) error

Put provides the Put method of tftp.Client.

type ClientCfg

type ClientCfg struct {
	Host    string
	Port    string
	Client  ClientIf
	Mode    tftp.TransferMode
	Rexmt   tftp.ClientOpt
	Timeout tftp.ClientOpt
}

ClientCfg holds all configuration values of a client.

type ClientIf

type ClientIf interface {
	Put(string, io.Reader, int64) error
	Get(string) (Response, error)
}

ClientIf serves as interface which allows mocking of tftp.Client for testing and usage of the real implementation, depending on the use-case.

type Flags

type Flags struct {
	Cmd       string
	Mode      string
	PortRange string
}

Flags provides the flags used in ./cmds/core/tftp. For more details, see the main-function in ./cmds/core/tftp/main.go.

type RealResponse

type RealResponse struct {
	*tftp.Response
}

RealResponse implements the Response interface and uses the tftp.Response as member to interact with the real library.

func (*RealResponse) Read

func (r *RealResponse) Read(b []byte) (int, error)

Read provides the Read function of tftp.Response.

func (*RealResponse) Size

func (r *RealResponse) Size() (int64, error)

Size provides the Size function of tftp.Response.

type Response

type Response interface {
	Read([]byte) (int, error)
	Size() (int64, error)
}

Response serves as interface which allows mocking of tftp.Response for testing and usage of the real implementation, depending on the use-case.

Jump to

Keyboard shortcuts

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