ftpclient

package
v1.15.0 Latest Latest
Warning

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

Go to latest
Published: Apr 15, 2024 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ErrorParamsEmpty liberr.CodeError = iota + liberr.MinPkgFTPClient
	ErrorValidatorError
	ErrorEndpointParser
	ErrorNotInitialized
	ErrorFTPConnection
	ErrorFTPConnectionCheck
	ErrorFTPLogin
	ErrorFTPCommand
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// Hostname define the host/port to connect to server.
	Hostname string `mapstructure:"hostname" json:"hostname" yaml:"hostname" toml:"hostname" validate:"required,hostname_rfc1123"`

	// Login define the login to use in login command.
	Login string `mapstructure:"login" json:"login" yaml:"login" toml:"login"`

	// Password defined the password to use in the login command.
	Password string `mapstructure:"password" json:"password" yaml:"password" toml:"password"`

	// ConnTimeout define a timeout duration for each connection (this is a global connection : connection, store contents, read content, ...).
	ConnTimeout time.Duration `mapstructure:"conn_timeout" json:"conn_timeout" yaml:"conn_timeout" toml:"conn_timeout"`

	// TimeZone force the time zone to use for the connection to the server.
	TimeZone ConfigTimeZone `mapstructure:"timezone" json:"timezone" yaml:"timezone" toml:"timezone"`

	// DisableUTF8 disable the UTF8 translation into the connection to the server.
	DisableUTF8 bool `mapstructure:"disable_utf8" json:"disable_utf8" yaml:"disable_utf8" toml:"disable_utf8"`

	// DisableEPSV disable the EPSV command into the connection to the server. (cf RFC 2428).
	DisableEPSV bool `mapstructure:"disable_epsv" json:"disable_epsv" yaml:"disable_epsv" toml:"disable_epsv"`

	// DisableMLSD disable the MLSD command into the connection to the server. (cf RFC 3659)
	DisableMLSD bool `mapstructure:"disable_mlsd" json:"disable_mlsd" yaml:"disable_mlsd" toml:"disable_mlsd"`

	// EnableMDTM enable the MDTM command into the connection to the server. (cf RFC 3659)
	EnableMDTM bool `mapstructure:"enable_mdtm" json:"enable_mdtm" yaml:"enable_mdtm" toml:"enable_mdtm"`

	// ForceTLS defined if the TLS connection must be forced or not.
	ForceTLS bool `mapstructure:"force_tls" json:"force_tls" yaml:"force_tls" toml:"force_tls"`

	// TLS define the client TLS config used if needed or forced
	TLS libtls.Config `mapstructure:"tls" json:"tls" yaml:"tls" toml:"tls"`
	// contains filtered or unexported fields
}

func (*Config) New

func (c *Config) New() (*libftp.ServerConn, liberr.Error)

func (*Config) RegisterContext

func (c *Config) RegisterContext(fct func() context.Context)

func (*Config) RegisterDefaultTLS

func (c *Config) RegisterDefaultTLS(fct func() libtls.TLSConfig)

func (*Config) Validate

func (c *Config) Validate() liberr.Error

Validate allow checking if the config' struct is valid with the awaiting model

type ConfigTimeZone

type ConfigTimeZone struct {
	Name   string `mapstructure:"name" json:"name" yaml:"name" toml:"name"`
	Offset int    `mapstructure:"offset" json:"offset" yaml:"offset" toml:"offset"`
}

type FTPClient

type FTPClient interface {
	// Connect establish the connection to server with the given configuration registered.
	Connect() liberr.Error

	// Check try to retrieve a valid connection to the server and send an NOOP command to check the connection.
	Check() liberr.Error

	// Close send the QUID command to the server if the connection is valid (cf Check).
	Close()

	// NameList issues an NLST FTP command.
	NameList(path string) ([]string, liberr.Error)

	// List issues a LIST FTP command.
	List(path string) ([]*libftp.Entry, liberr.Error)

	// ChangeDir issues a CWD FTP command, which changes the current directory to the specified path.
	ChangeDir(path string) liberr.Error

	// CurrentDir issues a PWD FTP command, which Returns the path of the current directory.
	CurrentDir() (string, liberr.Error)

	// FileSize issues a SIZE FTP command, which Returns the size of the file.
	FileSize(path string) (int64, liberr.Error)

	// GetTime issues the MDTM FTP command to obtain the file modification time.
	// It returns a UTC time.
	GetTime(path string) (time.Time, liberr.Error)

	// SetTime issues the MFMT FTP command to set the file modification time.
	// Also it can use a non-standard form of the MDTM command supported by the VsFtpd server instead of MFMT for the same purpose.
	// See "mdtm_write" in https://security.appspot.com/vsftpd/vsftpd_conf.html
	SetTime(path string, t time.Time) liberr.Error

	// Retr issues a RETR FTP command to fetch the specified file from the remote FTP server.
	// The returned ReadCloser must be closed to cleanup the FTP data connection.
	Retr(path string) (*libftp.Response, liberr.Error)

	// RetrFrom issues a RETR FTP command to fetch the specified file from the remote FTP server,
	// the server will not send the offset first bytes of the file.
	// The returned ReadCloser must be closed to cleanup the FTP data connection.
	RetrFrom(path string, offset uint64) (*libftp.Response, error)

	// Stor issues a STOR FTP command to store a file to the remote FTP server.
	// Stor creates the specified file with the content of the io.Reader.
	// Hint: io.Pipe() can be used if an io.Writer is required.
	Stor(path string, r io.Reader) liberr.Error

	// StorFrom issues a STOR FTP command to store a file to the remote FTP server.
	// Stor creates the specified file with the content of the io.Reader, writing on the server will start at the given file offset.
	// Hint: io.Pipe() can be used if an io.Writer is required.
	StorFrom(path string, r io.Reader, offset uint64) liberr.Error

	// Append issues a APPE FTP command to store a file to the remote FTP server.
	// If a file already exists with the given path, then the content of the io.Reader is appended.
	// Otherwise, a new file is created with that content. Hint: io.Pipe() can be used if an io.Writer is required.
	Append(path string, r io.Reader) liberr.Error

	// Rename renames a file on the remote FTP server.
	Rename(from, to string) liberr.Error

	// Delete issues a DELE FTP command to delete the specified file from the remote FTP server.
	Delete(path string) liberr.Error

	// RemoveDirRecur deletes a non-empty folder recursively using RemoveDir and Delete.
	RemoveDirRecur(path string) liberr.Error

	// MakeDir issues a MKD FTP command to create the specified directory on the remote FTP server.
	MakeDir(path string) liberr.Error

	// RemoveDir issues a RMD FTP command to remove the specified directory from the remote FTP server.
	RemoveDir(path string) liberr.Error

	//Walk prepares the internal walk function so that the caller can begin traversing the directory.
	Walk(root string) (*libftp.Walker, liberr.Error)
}

func New

func New(cfg *Config) (FTPClient, liberr.Error)

Jump to

Keyboard shortcuts

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