sftp

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 9, 2026 License: MIT Imports: 23 Imported by: 0

Documentation

Overview

Package sftp provides a capability-based SFTP adapter using pkg/sftp and golang.org/x/crypto/ssh.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Adapter

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

Adapter stores files beneath one remote SFTP directory.

func New deprecated

func New(ctx context.Context, configuration Config) (*Adapter, error)

New validates SSH security settings and opens the initial SFTP session.

Deprecated: use Open, which names the caller-owned session acquisition.

func Open added in v1.1.0

func Open(ctx context.Context, configuration Config) (*Adapter, error)

Open validates SSH security settings and opens a caller-owned SFTP session.

func (*Adapter) Capabilities

func (a *Adapter) Capabilities() filesystem.CapabilitySet

Capabilities reports protocol and server-extension support.

func (*Adapter) Checksum

func (a *Adapter) Checksum(ctx context.Context, logicalPath filesystem.Path, algorithm filesystem.ChecksumAlgorithm) (filesystem.Checksum, error)

Checksum streams a remote file through the requested local digest.

func (*Adapter) Close

func (a *Adapter) Close() error

Close releases the current SFTP and SSH connections.

func (*Adapter) Copy

func (a *Adapter) Copy(ctx context.Context, source, destination filesystem.Path, options filesystem.CopyOptions) error

Copy streams into a temporary destination and requires explicit overwrite because SFTP has no portable conditional destination operation.

func (*Adapter) Delete

func (a *Adapter) Delete(ctx context.Context, logicalPath filesystem.Path) error

Delete removes a file without replaying an ambiguous request.

func (*Adapter) List

List returns a bounded deterministic snapshot and reconnects once if the connection is lost while walking.

func (*Adapter) Move

func (a *Adapter) Move(ctx context.Context, source, destination filesystem.Path, options filesystem.MoveOptions) error

Move uses the POSIX rename extension and never emulates rename with copy-and-delete.

func (*Adapter) Open

func (a *Adapter) Open(ctx context.Context, logicalPath filesystem.Path) (io.ReadCloser, error)

Open opens a remote stream and reconnects once if opening fails because the current connection was already lost.

func (*Adapter) OpenRange

func (a *Adapter) OpenRange(ctx context.Context, logicalPath filesystem.Path, byteRange filesystem.ByteRange) (io.ReadCloser, error)

OpenRange opens a bounded range without buffering the whole remote file.

func (*Adapter) OpenWriter

func (a *Adapter) OpenWriter(ctx context.Context, logicalPath filesystem.Path, options filesystem.WriteOptions) (io.WriteCloser, error)

OpenWriter returns a streaming writer that publishes its remote temporary file on Close without replaying an uncertain upload.

func (*Adapter) SetMetadata

func (a *Adapter) SetMetadata(context.Context, filesystem.Path, map[string]string) error

SetMetadata returns a typed unsupported error.

func (*Adapter) SetVisibility

SetVisibility returns a typed unsupported error.

func (*Adapter) Stat

func (a *Adapter) Stat(ctx context.Context, logicalPath filesystem.Path) (filesystem.Metadata, error)

Stat retrieves metadata and reconnects once after a lost connection.

func (*Adapter) TemporaryURL

TemporaryURL returns a typed unsupported error.

func (*Adapter) Visibility

Visibility returns a typed unsupported error.

func (*Adapter) Write

func (a *Adapter) Write(ctx context.Context, logicalPath filesystem.Path, source io.Reader, options filesystem.WriteOptions) (filesystem.Metadata, error)

Write publishes through a temporary file. A consumed source is never replayed after connection loss.

type Config

type Config struct {
	// Address is the SSH server host and port.
	Address string
	// User is the SSH username.
	User string
	// Auth contains one or more SSH authentication methods.
	Auth []ssh.AuthMethod
	// HostKeyCallback verifies the server host key and is mandatory.
	HostKeyCallback ssh.HostKeyCallback
	// Root is the absolute remote directory containing all logical paths.
	Root string
	// Timeout bounds TCP dialing; zero selects 30 seconds. The operation
	// context's cancellation or deadline bounds SSH setup.
	Timeout time.Duration
	// MaxListEntries bounds one listing; zero selects 10,000.
	MaxListEntries int
}

Config contains SSH connection and remote-root settings.

Jump to

Keyboard shortcuts

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