Documentation
¶
Overview ¶
Package sftp provides an SFTP backend for omnistorage.
Basic usage with password authentication:
backend, err := sftp.New(sftp.Config{
Host: "example.com",
User: "username",
Password: "password",
})
With SSH key authentication:
backend, err := sftp.New(sftp.Config{
Host: "example.com",
User: "username",
KeyFile: "/path/to/id_rsa",
})
Index ¶
- Variables
- func NewFromConfig(configMap map[string]string) (omnistorage.Backend, error)
- type Backend
- func (b *Backend) Close() error
- func (b *Backend) Copy(ctx context.Context, src, dst string) error
- func (b *Backend) Delete(ctx context.Context, p string) error
- func (b *Backend) Exists(ctx context.Context, p string) (bool, error)
- func (b *Backend) Features() omnistorage.Features
- func (b *Backend) List(ctx context.Context, prefix string) ([]string, error)
- func (b *Backend) Mkdir(ctx context.Context, p string) error
- func (b *Backend) Move(ctx context.Context, src, dst string) error
- func (b *Backend) NewReader(ctx context.Context, p string, opts ...omnistorage.ReaderOption) (io.ReadCloser, error)
- func (b *Backend) NewWriter(ctx context.Context, p string, opts ...omnistorage.WriterOption) (io.WriteCloser, error)
- func (b *Backend) Rmdir(ctx context.Context, p string) error
- func (b *Backend) Stat(ctx context.Context, p string) (omnistorage.ObjectInfo, error)
- type Config
Constants ¶
This section is empty.
Variables ¶
var ( ErrHostRequired = errors.New("sftp: host is required") ErrUserRequired = errors.New("sftp: user is required") )
Errors specific to the SFTP backend.
Functions ¶
func NewFromConfig ¶
func NewFromConfig(configMap map[string]string) (omnistorage.Backend, error)
NewFromConfig creates a new SFTP backend from a config map. This is used by the omnistorage registry.
Types ¶
type Backend ¶
type Backend struct {
// contains filtered or unexported fields
}
Backend implements omnistorage.ExtendedBackend for SFTP.
func (*Backend) Features ¶
func (b *Backend) Features() omnistorage.Features
Features returns the capabilities of the SFTP backend.
func (*Backend) NewReader ¶
func (b *Backend) NewReader(ctx context.Context, p string, opts ...omnistorage.ReaderOption) (io.ReadCloser, error)
NewReader creates a reader for the given path.
func (*Backend) NewWriter ¶
func (b *Backend) NewWriter(ctx context.Context, p string, opts ...omnistorage.WriterOption) (io.WriteCloser, error)
NewWriter creates a writer for the given path.
func (*Backend) Stat ¶
func (b *Backend) Stat(ctx context.Context, p string) (omnistorage.ObjectInfo, error)
Stat returns metadata about an object.
type Config ¶
type Config struct {
// Host is the SFTP server hostname or IP address (required).
Host string
// Port is the SSH port. Default: 22.
Port int
// User is the SSH username (required).
User string
// Password is the SSH password.
// Either Password or KeyFile must be provided.
Password string
// KeyFile is the path to an SSH private key file.
// Either Password or KeyFile must be provided.
KeyFile string
// KeyPassphrase is the passphrase for encrypted private keys.
KeyPassphrase string
// Root is the base directory on the remote server.
// All paths are relative to this directory.
Root string
// KnownHostsFile is the path to the known_hosts file.
// If empty, host key verification is disabled (insecure).
KnownHostsFile string
// Timeout is the connection timeout in seconds.
// Default: 30.
Timeout int
// Concurrency is the maximum number of concurrent operations.
// Default: 5.
Concurrency int
}
Config holds configuration for the SFTP backend.
func ConfigFromEnv ¶
func ConfigFromEnv() Config
ConfigFromEnv creates a Config from environment variables. Environment variables:
- OMNISTORAGE_SFTP_HOST: server hostname
- OMNISTORAGE_SFTP_PORT: SSH port (default: 22)
- OMNISTORAGE_SFTP_USER: username
- OMNISTORAGE_SFTP_PASSWORD: password
- OMNISTORAGE_SFTP_KEY_FILE: path to private key
- OMNISTORAGE_SFTP_KEY_PASSPHRASE: passphrase for encrypted key
- OMNISTORAGE_SFTP_ROOT: base directory
- OMNISTORAGE_SFTP_KNOWN_HOSTS: path to known_hosts file
- OMNISTORAGE_SFTP_TIMEOUT: connection timeout in seconds
func ConfigFromMap ¶
ConfigFromMap creates a Config from a string map. Supported keys:
- host: server hostname (required)
- port: SSH port (default: 22)
- user: username (required)
- pass or password: password
- key_file: path to private key
- key_passphrase: passphrase for encrypted key
- root: base directory
- known_hosts: path to known_hosts file
- timeout: connection timeout in seconds
- concurrency: maximum concurrent operations
func DefaultConfig ¶
func DefaultConfig() Config
DefaultConfig returns a Config with default values.