sftp

package
v0.16.6 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2026 License: MIT Imports: 11 Imported by: 1

README

SFTP backend

This backend connects to an upstream SSH/SFTP server.

Parameters

  • hostname: The upstream server address, with its port (e.g. 192.168.1.10:22).
  • username: The SSH user.
  • password: The SSH password.
  • One of the host key verification parameters below.

Host key verification

The upstream server's host key is verified to protect against man-in-the-middle attacks. You must configure exactly one of the following parameters:

  • known_hosts: path to an OpenSSH known_hosts file containing the upstream server's key (e.g. generated with ssh-keyscan -H host >> known_hosts).
  • host_key: the upstream server's public key pinned inline, in authorized_keys / known_hosts line format (e.g. ssh-ed25519 AAAA...).
  • insecure_ignore_host_key: set to "true" to disable host key verification entirely. This is unsafe (it exposes the connection to man-in-the-middle attacks) and should only be used in trusted networks or for testing.

If none of these is set, the connection is refused.

Configuration

{
  "accesses": [
    {
      "user": "sftp",
      "pass": "sftp",
      "fs": "sftp",
      "shared": true,
      "params": {
        "hostname": "192.168.1.10:22",
        "username": "user",
        "password": "password",
        "known_hosts": "/home/ftpserver/.ssh/known_hosts"
      }
    }
  ]
}

With shared enabled, a single SSH connection is used for all the FTP sessions of this access.

Documentation

Overview

Package sftp provides an SFTP connection layer

Index

Constants

This section is empty.

Variables

View Source
var ErrNoHostKeyVerification = errors.New(
	`sftp: no host key verification configured: set "known_hosts" or "host_key", ` +
		`or set "insecure_ignore_host_key" to "true" to disable verification (unsafe)`)

ErrNoHostKeyVerification is returned when no host key verification method has been configured. Verifying the host key protects against man-in-the-middle attacks, so it must either be set up (with "known_hosts" or "host_key") or explicitly disabled (with "insecure_ignore_host_key").

Functions

func LoadFs

func LoadFs(access *confpar.Access, logger *slog.Logger) (afero.Fs, error)

LoadFs loads a file system from an access description

Types

type ConnectionError added in v0.8.0

type ConnectionError struct {
	Source error
}

ConnectionError is returned when a connection occurs while connecting to the SFTP server

func (ConnectionError) Error added in v0.8.0

func (err ConnectionError) Error() string

type Fs added in v0.16.6

type Fs struct {
	afero.Fs
	// contains filtered or unexported fields
}

Fs is the SFTP file system. It also closes the SFTP client and its SSH connection, which afero's sftpfs can't do.

func (*Fs) Close added in v0.16.6

func (f *Fs) Close() error

Close closes the SFTP client and the SSH connection. It can be called several times.

Jump to

Keyboard shortcuts

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