arksftp

package
v0.3.0 Latest Latest
Warning

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

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

Documentation

Overview

Package arksftp implements ark.Backend over an SFTP connection.

One Backend owns one SSH connection and one SFTP client. Requests are multiplexed over that single connection; there is no pool. The Repository concurrency bound (ark.WithConcurrency, runtime.NumCPU times two by default) caps how many requests are in flight, so the caller sizes the load on that one connection.

Secrets never live in Config or in a URI. The password comes from ARK_SFTP_PASSWORD and a key passphrase from ARK_SFTP_KEY_PASSPHRASE; see EnvPassword and EnvKeyPassphrase.

Index

Constants

View Source
const (
	// EnvPassword holds the SSH password, used when neither the agent nor an
	// identity file authenticates.
	EnvPassword = "ARK_SFTP_PASSWORD" //nolint:gosec // env var name, not a credential
	// EnvKeyPassphrase unlocks an encrypted IdentityFile.
	EnvKeyPassphrase = "ARK_SFTP_KEY_PASSPHRASE" //nolint:gosec // env var name, not a credential
)

Secrets are read from the environment, never from Config or a URI.

Variables

This section is empty.

Functions

This section is empty.

Types

type Backend

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

Backend implements ark.Backend backed by an SFTP server. All methods are safe for concurrent use via the underlying SSH/SFTP multiplexing.

func New

func New(cfg Config) (*Backend, error)

New connects to the SFTP server described by cfg and returns a ready Backend. The caller closes it with Backend.Close.

func (*Backend) Close

func (b *Backend) Close() error

Close closes the SFTP client and the underlying SSH connection.

func (*Backend) Delete

func (b *Backend) Delete(ctx context.Context, h ark.Handle) error

Delete removes the object identified by h. Removing a non-existent object is not an error.

func (*Backend) Exists

func (b *Backend) Exists(ctx context.Context, h ark.Handle) (bool, error)

Exists reports whether the object identified by h is present.

func (*Backend) Get

func (b *Backend) Get(ctx context.Context, h ark.Handle) (io.ReadCloser, error)

Get returns a ReadCloser for the object stored under h. Callers must close the returned reader.

func (*Backend) List

func (b *Backend) List(ctx context.Context, t ark.HandleType, fn func(ark.BlobInfo) error) error

List walks the namespace of t and calls fn for every object it holds. An absent namespace is empty, not an error.

func (*Backend) Put

func (b *Backend) Put(ctx context.Context, h ark.Handle, r io.Reader) error

Put writes r to a temporary name in the target directory and renames it into place with posix-rename, so a reader never sees a partial object. It is idempotent: an existing object is replaced.

func (*Backend) Stat

func (b *Backend) Stat(ctx context.Context, h ark.Handle) (ark.BlobInfo, error)

Stat returns metadata for the object stored under h.

func (*Backend) Sync added in v0.2.0

func (b *Backend) Sync(ctx context.Context) error

Sync is a no-op: Put and Delete already fsync every object and directory they touch on the server (with fsync@openssh.com). A deferred flush would cost an open, fsync and close round trip per object, more than it saves.

type Config

type Config struct {
	// Host is the remote hostname, IP address, or an ssh_config Host alias
	// whose HostName replaces it.
	Host string
	// Port is the SSH port. Falls back to ssh_config, then to 22.
	Port int
	// User is the SSH username. Falls back to ssh_config, then to the
	// current OS user.
	User string
	// Path is the repository root directory on the remote server.
	Path string
	// IdentityFile is the path to a PEM-encoded private key file.
	// Falls back to ssh_config, then to ~/.ssh/id_rsa, id_ecdsa and
	// id_ed25519.
	IdentityFile string
	// KnownHostsFile is the known_hosts file used to verify the host key.
	// Defaults to ~/.ssh/known_hosts.
	KnownHostsFile string
	// InsecureIgnoreHostKey skips host key verification. It exposes the
	// connection to man-in-the-middle attacks and is meant for tests and
	// throwaway environments only.
	InsecureIgnoreHostKey bool
	// Timeout bounds the TCP and SSH handshake. Defaults to 30s when zero.
	Timeout time.Duration
}

Config describes how to reach an SFTP server. Zero values fall back to the documented defaults. It holds no secrets.

Jump to

Keyboard shortcuts

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