sftp

package
v0.0.0-...-753ccf0 Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2026 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultPort is the standard SSH/SFTP port.
	DefaultPort = 22

	// DefaultTimeout is the standard timeout for SSH dial and handshake.
	DefaultTimeout = 30 * time.Second

	// DefaultDirMode is the default POSIX permission for directory creation.
	DefaultDirMode os.FileMode = 0755

	// DefaultFileMode is the default POSIX permission for file creation.
	DefaultFileMode os.FileMode = 0644
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// Name is the driver identifier (e.g. "sftp-primary", "sftp-backup"). Defaults to "sftp".
	Name string

	// Host is the remote SSH host or IP address. Required.
	Host string

	// Port is the remote SSH port. Defaults to 22.
	Port int

	// User is the SSH login username. Required.
	User string

	// Password is the SSH login password. Optional if PrivateKeyPEM is provided.
	Password string

	// PrivateKeyPEM contains raw RSA, ECDSA, or Ed25519 private key PEM bytes. Optional if Password is provided.
	PrivateKeyPEM []byte

	// PrivateKeyPassphrase is the decryption passphrase for encrypted private keys.
	PrivateKeyPassphrase string

	// HostKey is the expected remote server public key for strict host key verification.
	HostKey ssh.PublicKey

	// InsecureIgnoreHostKey disables SSH host key verification (recommended only for dev/testing).
	InsecureIgnoreHostKey bool

	// BaseDir is the root directory path on the remote SFTP server where blobs are stored.
	BaseDir string

	// EnableSidecarMeta persists <key>.meta.json sidecar files on the SFTP server for metadata fidelity.
	EnableSidecarMeta bool

	// PublicBaseURL is an optional base URL for public CDN/HTTP gateway access (e.g. "https://cdn.example.com").
	PublicBaseURL string

	// Timeout is the SSH network connection and handshake timeout. Defaults to 30 seconds.
	Timeout time.Duration

	// DirMode specifies the file mode permissions used when creating remote directories. Defaults to 0755.
	DirMode os.FileMode

	// FileMode specifies the file mode permissions used when creating remote files. Defaults to 0644.
	FileMode os.FileMode
}

Config specifies configuration parameters for the SFTP storage driver.

func (*Config) Validate

func (c *Config) Validate() error

Validate sanitizes the configuration, enforces required fields, and applies default values.

type Driver

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

Driver implements the blobkit.Driver interface for remote SFTP servers.

func NewDriver

func NewDriver(cfg Config) (*Driver, error)

NewDriver constructs and validates an SFTP storage driver.

func (*Driver) AbortMultipart

func (d *Driver) AbortMultipart(ctx context.Context, key string, uploadID string) error

AbortMultipart is unsupported on native SFTP.

func (*Driver) Capabilities

func (d *Driver) Capabilities() blobkit.Capability

Capabilities returns the feature bitmask supported by the SFTP driver.

func (*Driver) Close

func (d *Driver) Close() error

Close gracefully terminates open SFTP and SSH network connections.

func (*Driver) CompleteMultipart

func (d *Driver) CompleteMultipart(ctx context.Context, obj *blobkit.Object, uploadID string, parts []blobkit.CompletedPart) (*blobkit.Object, error)

CompleteMultipart is unsupported on native SFTP.

func (*Driver) Copy

func (d *Driver) Copy(ctx context.Context, srcKey, dstKey string) error

Copy duplicates an object server-side using streaming across SFTP files.

func (*Driver) CreateMultipart

func (d *Driver) CreateMultipart(ctx context.Context, obj *blobkit.Object, opts blobkit.PutOptions) (string, error)

CreateMultipart is unsupported on native SFTP.

func (*Driver) Delete

func (d *Driver) Delete(ctx context.Context, key string) error

Delete permanently removes a file and its associated .meta.json sidecar from the SFTP server.

func (*Driver) DeleteBatch

func (d *Driver) DeleteBatch(ctx context.Context, keys []string) ([]string, error)

DeleteBatch removes multiple keys concurrently using a bounded worker pool.

func (*Driver) Get

Get opens a remote SFTP file and streams its content, supporting HTTP byte-range seeks.

func (*Driver) Head

func (d *Driver) Head(ctx context.Context, key string) (*blobkit.Object, error)

Head inspects a remote SFTP file and loads metadata without reading the file body.

func (*Driver) List

List queries objects on the remote SFTP server matching prefix and delimiter filters.

func (*Driver) ListParts

func (d *Driver) ListParts(ctx context.Context, key string, uploadID string) ([]blobkit.CompletedPart, error)

ListParts is unsupported on native SFTP.

func (*Driver) Name

func (d *Driver) Name() string

Name returns the driver identifier.

func (*Driver) PresignGet

func (d *Driver) PresignGet(ctx context.Context, key string, opts blobkit.PresignOptions) (*blobkit.PresignedURL, error)

PresignGet is unsupported on native SFTP.

func (*Driver) PresignPut

func (d *Driver) PresignPut(ctx context.Context, key string, opts blobkit.PresignOptions) (*blobkit.PresignedURL, error)

PresignPut is unsupported on native SFTP.

func (*Driver) Put

func (d *Driver) Put(ctx context.Context, obj *blobkit.Object, r io.Reader, opts blobkit.PutOptions) (*blobkit.Object, error)

Put streams an object to the remote SFTP server, writing to a temporary file before atomically renaming to prevent partial reads.

func (*Driver) ResolveURL

func (d *Driver) ResolveURL(key string) (string, error)

ResolveURL builds a public access or CDN URL if configured.

func (*Driver) UploadPart

func (d *Driver) UploadPart(ctx context.Context, key string, uploadID string, partNumber int32, r io.Reader, size int64) (string, error)

UploadPart is unsupported on native SFTP.

Jump to

Keyboard shortcuts

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