sftp

package module
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Sep 9, 2026 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Overview

Package sftp is a sink that puts things on a server over SSH.

It is the one a building already has. There is no bucket to stand up, no service to run and no credential to mint: there is a machine with a disk, and an account on it.

The host key is checked

Options.KnownHosts is required. A host key nobody checks is a sink that will one day be somebody else, and the files this carries are the ones nobody is watching. Turning it off is possible and the field is called Options.InsecureIgnoreHostKey, so that it is a decision somebody wrote down rather than a default nobody noticed.

It writes beside the name and then renames

The same as the directory sink, for the same reason: anything watching that directory -- a person, a script, a second wick carrying onward -- sees the whole file or no file, never a growing one.

Index

Constants

View Source
const DefaultTimeout = 30 * time.Second

DefaultTimeout is how long the connection may take to be made.

It is about reaching the server, not about carrying a file: a transfer of half a gigabyte on a slow link is meant to take a long time, and a deadline on the whole thing would be a size limit written as a clock.

View Source
const Kind = "sftp"

Kind is what a configuration calls this one.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client interface {
	Create(path string) (io.WriteCloser, error)
	Stat(path string) (os.FileInfo, error)
	Remove(path string) error
	Rename(oldname, newname string) error
	MkdirAll(path string) error
	Close() error
}

Client is the part of an SFTP connection this package uses.

Narrowed to these six calls so that a test can make each of them fail without a server that has been talked into failing, and so that reading this says exactly what is asked of the other end.

type Options

type Options struct {
	// Address is the server, host and port. The port is 22 when it is not
	// said.
	Address string

	// User is the account on it.
	User string

	// KeyFile is a private key, and KeyPassphrase is what it is locked with.
	KeyFile       string
	KeyPassphrase string

	// Password is the other way. One of the two, not both.
	Password string

	// KnownHosts is the file the server's key is checked against. Required
	// unless InsecureIgnoreHostKey.
	KnownHosts string

	// InsecureIgnoreHostKey stops the server's key being checked. It is named
	// this way on purpose.
	InsecureIgnoreHostKey bool

	// Path is the directory things go under, and is where the account lands
	// when it is not said.
	Path string

	// Timeout is how long the connection may take to be made. Nothing means
	// [DefaultTimeout].
	Timeout time.Duration

	// RateLimit is bytes per second, and is no limit when it is not said.
	RateLimit int64

	// Dial makes the connection, and is the real one when nil. It is here for
	// the same reason [Client] is an interface.
	Dial func(ctx context.Context, o Options) (Client, error)
}

type Sink

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

func New

func New(o Options) (*Sink, error)

func (*Sink) Close

func (s *Sink) Close() error

Close lets the connection go. The engine calls it on the sinks it made.

func (*Sink) Put

func (s *Sink) Put(ctx context.Context, name string, r io.Reader, want sink.Meta) error

func (*Sink) Stat

func (s *Sink) Stat(ctx context.Context, name string) (sink.Meta, error)

type Spec

type Spec struct {
	sink.Typed `yaml:",inline"`

	// Address is the server, host and port; the port is 22 when it is not
	// said. User is the account on it.
	Address string `yaml:"address"`
	User    string `yaml:"user"`

	// KeyFile is a private key and KeyPassphrase is what it is locked with.
	// Password is the other way. One of the two, not both. Write either as
	// "${env:...}" so that it is named in the file and not held in it.
	KeyFile       string `yaml:"key_file"`
	KeyPassphrase string `yaml:"key_passphrase"`
	Password      string `yaml:"password"`

	// KnownHosts is the file the server's key is checked against, and is
	// required: a host key nobody checks is a sink that will one day be
	// somebody else.
	KnownHosts string `yaml:"known_hosts"`
	// InsecureIgnoreHostKey stops it being checked. Named so that turning it
	// on is a decision somebody wrote down.
	InsecureIgnoreHostKey bool `yaml:"insecure_ignore_host_key"`

	// Path is the directory things go under, and is where the account lands
	// when it is not said.
	Path string `yaml:"path"`

	// Timeout is how long reaching the server may take. It is not a deadline
	// on carrying a file.
	Timeout time.Duration `yaml:"timeout"`

	// RateLimit is bytes per second; no limit when it is not said.
	RateLimit size.Bytes `yaml:"rate_limit"`
}

A Spec is what a configuration says about an sftp sink.

func (*Spec) New

func (s *Spec) New(ctx context.Context) (sink.Sink, error)

Jump to

Keyboard shortcuts

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