sftp

package
v0.12.0 Latest Latest
Warning

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

Go to latest
Published: Feb 14, 2021 License: BSD-2-Clause Imports: 17 Imported by: 0

Documentation

Overview

Package sftp implements repository storage in a directory on a remote server via the sftp protocol.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Join

func Join(parts ...string) string

Join joins the given paths and cleans them afterwards. This always uses forward slashes, which is required by sftp.

func ParseConfig

func ParseConfig(s string) (interface{}, error)

ParseConfig parses the string s and extracts the sftp config. The supported configuration formats are sftp://user@host[:port]/directory

and sftp:user@host:directory.  The directory will be path Cleaned and can
be an absolute path if it starts with a '/' (e.g.
sftp://user@host//absolute and sftp:user@host:/absolute).

Types

type Config

type Config struct {
	User, Host, Port, Path string

	Layout  string `option:"layout" help:"use this backend directory layout (default: auto-detect)"`
	Command string `option:"command" help:"specify command to create sftp connection"`
}

Config collects all information required to connect to an sftp server.

type SFTP

type SFTP struct {
	backend.Layout
	Config
	// contains filtered or unexported fields
}

SFTP is a backend in a directory accessed via SFTP.

func Create

func Create(ctx context.Context, cfg Config) (*SFTP, error)

Create creates an sftp backend as described by the config by running "ssh" with the appropriate arguments (or cfg.Command, if set). The function preExec is run just before, postExec just after starting a program.

func Open

func Open(ctx context.Context, cfg Config) (*SFTP, error)

Open opens an sftp backend as described by the config by running "ssh" with the appropriate arguments (or cfg.Command, if set). The function preExec is run just before, postExec just after starting a program.

func (*SFTP) Close

func (r *SFTP) Close() error

Close closes the sftp connection and terminates the underlying command.

func (*SFTP) Delete added in v0.8.0

func (r *SFTP) Delete(ctx context.Context) error

Delete removes all data in the backend.

func (*SFTP) IsNotExist

func (r *SFTP) IsNotExist(err error) bool

IsNotExist returns true if the error is caused by a not existing file.

func (*SFTP) Join

func (r *SFTP) Join(p ...string) string

Join combines path components with slashes (according to the sftp spec).

func (*SFTP) List

func (r *SFTP) List(ctx context.Context, t restic.FileType, fn func(restic.FileInfo) error) error

List runs fn for each file in the backend which has the type t. When an error occurs (or fn returns an error), List stops and returns it.

func (*SFTP) Load

func (r *SFTP) Load(ctx context.Context, h restic.Handle, length int, offset int64, fn func(rd io.Reader) error) error

Load runs fn with a reader that yields the contents of the file at h at the given offset.

func (*SFTP) Location

func (r *SFTP) Location() string

Location returns this backend's location (the directory name).

func (*SFTP) ReadDir

func (r *SFTP) ReadDir(ctx context.Context, dir string) ([]os.FileInfo, error)

ReadDir returns the entries for a directory.

func (*SFTP) Remove

func (r *SFTP) Remove(ctx context.Context, h restic.Handle) error

Remove removes the content stored at name.

func (*SFTP) Save

func (r *SFTP) Save(ctx context.Context, h restic.Handle, rd restic.RewindReader) error

Save stores data in the backend at the handle.

func (*SFTP) Stat

func (r *SFTP) Stat(ctx context.Context, h restic.Handle) (restic.FileInfo, error)

Stat returns information about a blob.

func (*SFTP) Test

func (r *SFTP) Test(ctx context.Context, h restic.Handle) (bool, error)

Test returns true if a blob of the given type and name exists in the backend.

Jump to

Keyboard shortcuts

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