sftp

package
v1.5.1 Latest Latest
Warning

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

Go to latest
Published: Mar 22, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Overview

Package sftp implements a Backend backed by an SFTP remote server.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HostKeyFile

func HostKeyFile(file string) (ssh.HostKeyCallback, error)

HostKeyFile returns a host key callback that validates against a known_hosts file.

func HostKeyFingerprint

func HostKeyFingerprint(fingerprint string) (ssh.HostKeyCallback, error)

HostKeyFingerprint returns a host key callback that validates against a pinned SHA256 fingerprint (e.g. "SHA256:abc123...").

Types

type Backend

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

Backend stores repository data on a remote SFTP server.

func New

func New(host, port, user, basePath, keyFile, password, sshKey string, hostKeyCallback ssh.HostKeyCallback) (*Backend, error)

New connects to the SFTP server and returns a Backend rooted at basePath.

Authentication is attempted in order: inline SSH key (sshKey), SSH agent, public key file, password. At least one must be available.

hostKeyCallback can be obtained from HostKeyFingerprint() or HostKeyFile().

The basePath is the remote directory that serves as the repository root. The directory structure is created if it doesn't already exist.

func NewFromClients

func NewFromClients(sshClient *ssh.Client, sftpClient *sftp.Client, host, port, user, basePath string) (*Backend, error)

NewFromClients creates a Backend using pre-established SSH and SFTP clients. This is primarily useful for testing.

func (*Backend) Close

func (b *Backend) Close() error

func (*Backend) List

func (b *Backend) List(_ context.Context, t types.FileType, fn func(types.FileInfo) error) error

func (*Backend) Load

func (b *Backend) Load(_ context.Context, t types.FileType, name string, offset, length int64) (io.ReadCloser, error)

func (*Backend) Location

func (b *Backend) Location() string

func (*Backend) Remove

func (b *Backend) Remove(_ context.Context, t types.FileType, name string) error

func (*Backend) Save

func (b *Backend) Save(_ context.Context, t types.FileType, name string, rd io.Reader) error

func (*Backend) Stat

func (b *Backend) Stat(_ context.Context, t types.FileType, name string) (types.FileInfo, error)

Jump to

Keyboard shortcuts

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