ssh

package
v0.2.27 Latest Latest
Warning

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

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

Documentation

Overview

Package ssh implements the Storager interface on top of SSH/SFTP. The implementation is inspired by wal-g's pkg/storages/sh.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Host           string `mapstructure:"host"`             // required
	Port           int    `mapstructure:"port"`             // default 22
	User           string `mapstructure:"user"`             // required
	Password       string `mapstructure:"password"`         // auth: password
	PrivateKeyPath string `mapstructure:"private_key_path"` // auth: private key
	Prefix         string `mapstructure:"prefix"`           // remote root path
}

func NewConfig

func NewConfig() *Config

func (*Config) Validate

func (c *Config) Validate() error

type SFTPClient

type SFTPClient interface {
	ReadDir(path string) ([]os.FileInfo, error)
	Join(elem ...string) string
	Remove(path string) error
	RemoveDirectory(path string) error
	Stat(p string) (os.FileInfo, error)
	Open(path string) (*sftp.File, error)
	Create(path string) (*sftp.File, error)
	MkdirAll(path string) error
}

SFTPClient is the subset of *sftp.Client used by the storage. It is kept as an interface so the dependency surface stays small and explicit.

type Storage

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

func NewStorage

func NewStorage(cfg *Config) (*Storage, error)

func (*Storage) Close

func (s *Storage) Close() error

Close releases the shared SSH/SFTP connection. It must be called once by the lifecycle owner when the storage and all of its sub-storages are no longer needed; otherwise the connection, its receive goroutine and its socket leak until the process exits. SubStorage clones share the same connection, so only the connection is closed (not the clone) — Close is idempotent and safe to call more than once and before the connection has been established.

func (*Storage) Delete

func (s *Storage) Delete(ctx context.Context, filePaths ...string) error

func (*Storage) DeleteAll

func (s *Storage) DeleteAll(ctx context.Context, pathPrefix string) error

func (*Storage) Dirname

func (s *Storage) Dirname() string

func (*Storage) Exists

func (s *Storage) Exists(ctx context.Context, fileName string) (bool, error)

func (*Storage) GetCwd

func (s *Storage) GetCwd() string

func (*Storage) GetObject

func (s *Storage) GetObject(ctx context.Context, filePath string) (reader io.ReadCloser, err error)

func (*Storage) ListDir

func (s *Storage) ListDir(ctx context.Context) (files []string, dirs []storages.Storager, err error)

func (*Storage) PutObject

func (s *Storage) PutObject(ctx context.Context, filePath string, body io.Reader) error

func (*Storage) Stat

func (s *Storage) Stat(fileName string) (*domains.ObjectStat, error)

func (*Storage) SubStorage

func (s *Storage) SubStorage(subPath string, relative bool) storages.Storager

Jump to

Keyboard shortcuts

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