sftp

package
v3.0.0 Latest Latest
Warning

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

Go to latest
Published: Aug 1, 2026 License: MIT Imports: 24 Imported by: 0

Documentation

Overview

Package sftp provides a SFTP implementation of the storage interface.

Index

Constants

View Source
const Name = "sftp"

Name of the storage.

Variables

This section is empty.

Functions

func Get

func Get() storage.IStorage

Get returns a setup SFTP, or set it up.

func Set

func Set(s storage.IStorage)

Set sets the storage, primarily used for testing.

Types

type Config

type Config = ssh.ClientConfig

Config is the SFTP configuration.

type Option

type Option = sftp.ClientOption

Option is for the SFTP configuration.

type ResponseList

type ResponseList[T any] struct {
	Items []T `json:"items"`
}

ResponseList is the list response.

type SFTP

type SFTP struct {
	*storage.Storage

	Client *sftp.Client `json:"-" validate:"required,structonly"`

	// Conn is the underlying SSH transport carrying the SFTP subsystem.
	// Client.Close only tears down the SFTP channel, so callers need this to
	// release the TCP+SSH session — see Close.
	Conn *ssh.Client `json:"-" validate:"required,structonly"`

	// Target allows to set a static target. If it is empty, the target will be
	// dynamic - the one set at the operation (count, create, delete, etc) time.
	// Depending on the storage, target is a collection, a table, a bucket, etc.
	// For ElasticSearch, for example it doesn't have a concept of a database -
	// the target then is the index. Due to different cases of ElasticSearch
	// usage, the target can be static or dynamic - defined at the index time,
	// for example: log-{YYYY}-{MM}. For Redis, it isn't used at all.
	Target string `json:"-" validate:"omitempty,gt=0"`
	// contains filtered or unexported fields
}

SFTP storage definition.

func New

func New(ctx context.Context, addr string, cfg *Config, options ...Option) (*SFTP, error)

New creates a new SFTP storage.

NOTE: addr format is: host:port.

func (*SFTP) BulkCreate

func (s *SFTP) BulkCreate(
	ctx context.Context,
	_ string,
	items []storage.BulkItem,
	prm *create.Create,
	options ...storage.Func[*create.Create],
) (storage.BulkResult, error)

BulkCreate creates data with at most eight concurrent SFTP writes. Eight keeps network round trips moving without flooding one SSH connection.

func (*SFTP) Close

func (s *SFTP) Close() error

Close releases the SFTP client and the SSH transport underneath it. Closing only the client would leave the TCP+SSH session open for the lifetime of the process.

func (*SFTP) Count

func (s *SFTP) Count(ctx context.Context, target string, prm *count.Count, options ...storage.Func[*count.Count]) (int64, error)

Count returns the number of items in the storage.

func (*SFTP) Create

func (s *SFTP) Create(ctx context.Context, id, target string, v any, prm *create.Create, options ...storage.Func[*create.Create]) (string, error)

Create data.

NOTE: Not all storages returns the ID, neither all storages requires `id` to be set. You are better off setting the ID yourself.

func (*SFTP) Delete

func (s *SFTP) Delete(ctx context.Context, id, target string, prm *delete.Delete, options ...storage.Func[*delete.Delete]) error

Delete removes data.

func (*SFTP) GetClient

func (s *SFTP) GetClient() any

GetClient returns the client.

func (*SFTP) List

func (s *SFTP) List(ctx context.Context, target string, v any, prm *list.List, opts ...storage.Func[*list.List]) error

List data.

Search is a glob matched against filenames. Sort, Limit, Offset, and Fields are applied to the decoded documents after matching.

func (*SFTP) Retrieve

func (s *SFTP) Retrieve(ctx context.Context, id, target string, v any, prm *retrieve.Retrieve, options ...storage.Func[*retrieve.Retrieve]) error

Retrieve data.

func (*SFTP) Update

func (s *SFTP) Update(ctx context.Context, id, target string, v any, prm *update.Update, opts ...storage.Func[*update.Update]) error

Update data.

Jump to

Keyboard shortcuts

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