sftpfs

package
v0.1.0-rc.3 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2026 License: AGPL-3.0 Imports: 16 Imported by: 0

Documentation

Overview

Package sftpfs implements vfs.FS over SFTP (seedboxes, NAS), with pinned host keys (TOFU confirmed by the user), keepalives and lazy reconnection.

Index

Constants

This section is empty.

Variables

View Source
var (
	KeepaliveInterval = 30 * time.Second
	KeepaliveTimeout  = 15 * time.Second
)

Tunables (variables for tests).

View Source
var ErrAuth = errors.New("sftp: authentication failed")

ErrAuth is returned when the server rejects the credentials.

View Source
var ErrClosed = errors.New("sftp: source closed")

ErrClosed is returned after Close.

Functions

func New

func New(ctx context.Context, cfg Config) (vfs.FS, error)

New connects to the server (verifying the host key) and returns the source. A missing or different host key yields *HostKeyError.

func Probe

func Probe(ctx context.Context, cfg Config) (string, error)

Probe connects only far enough to obtain the server's host key fingerprint ("SHA256:..."), for the user confirmation flow. No authentication is made.

Types

type Config

type Config struct {
	Host       string
	Port       int // default 22
	User       string
	Password   string
	PrivateKey []byte // PEM (OpenSSH format accepted)
	Passphrase string
	HostKey    string // "SHA256:..." fingerprint, required
	Root       string // absolute remote path
	Timeout    time.Duration
}

Config describes an SFTP source.

type FS

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

FS is an SFTP source.

func (*FS) Close

func (f *FS) Close() error

Close closes the connection; the source cannot be used afterwards.

func (*FS) InputURL

func (f *FS) InputURL(string) string

InputURL returns "": the server proxies SFTP files to FFmpeg over HTTP.

func (*FS) Open

func (f *FS) Open(ctx context.Context, name string) (vfs.File, error)

Open opens a regular file. ctx is used for reconnections during reads.

func (*FS) Ping

func (f *FS) Ping(ctx context.Context) error

Ping stats the root.

func (*FS) ReadDir

func (f *FS) ReadDir(ctx context.Context, dir string) ([]vfs.Entry, error)

ReadDir lists the direct children of dir, sorted by name.

func (*FS) Stat

func (f *FS) Stat(ctx context.Context, name string) (vfs.Entry, error)

Stat describes name.

func (*FS) Walk

func (f *FS) Walk(ctx context.Context, dir string, fn func(vfs.Entry) error) error

Walk lists entries below dir (dir excluded), parents before children. Unreadable sub-directories are skipped; symlinked directories are listed but not descended into.

type HostKeyError

type HostKeyError struct {
	Fingerprint string
	Mismatch    bool
}

HostKeyError is returned when the server's host key is not pinned yet (Mismatch false: show Fingerprint to the user for confirmation) or differs from the pinned one (Mismatch true: possible spoofing).

func (*HostKeyError) Error

func (e *HostKeyError) Error() string

Jump to

Keyboard shortcuts

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