sftpfs

package module
v0.0.0-...-c93eabe Latest Latest
Warning

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

Go to latest
Published: Dec 13, 2024 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package sftpfs implements a SFTP client file system.

Index

Constants

View Source
const (
	Prefix    = "sftp://"
	Separator = "/"
)

Variables

This section is empty.

Functions

func AcceptAnyHostKey

func AcceptAnyHostKey(hostname string, remote net.Addr, key ssh.PublicKey) error

AcceptAnyHostKey can be passed as hostKeyCallback to Dial to accept any SSH public key from a remote host.

func Dial

func Dial(ctx context.Context, address string, credentialsCallback CredentialsCallback, hostKeyCallback ssh.HostKeyCallback) (fs.FileSystem, error)

Dial dials a new SFTP connection without registering it as file system.

The passed address can be a URL with scheme `sftp:` or just a host name. If no port is provided in the address, then port 22 will be used. The address can contain a username or a username and password.

func DialAndRegister

func DialAndRegister(ctx context.Context, address string, credentialsCallback CredentialsCallback, hostKeyCallback ssh.HostKeyCallback) (fs.FileSystem, error)

DialAndRegister dials a new SFTP connection and register it as file system.

The passed address can be a URL with scheme `sftp:` or just a host name. If no port is provided in the address, then port 22 will be used. The address can contain a username or a username and password.

func EnsureRegistered

func EnsureRegistered(ctx context.Context, address string, credentialsCallback CredentialsCallback, hostKeyCallback ssh.HostKeyCallback) (free func() error, err error)

EnsureRegistered first checks if a SFTP file system with the passed address is already registered. If not, then a new connection is dialed and registered. The returned free function has to be called to decrease the file system's reference count and close it when the reference count reaches 0. The returned free function will never be nil.

Types

type CredentialsCallback

type CredentialsCallback func(*url.URL) (username, password string, err error)

CredentialsCallback is called by Dial to get the username and password for a SFTP connection.

func Password

func Password(password string) CredentialsCallback

Password returns a CredentialsCallback that always returns the provided password together with the username from the URL that is passed to the callback.

func UsernameAndPassword

func UsernameAndPassword(username, password string) CredentialsCallback

UsernameAndPassword returns a CredentialsCallback that always returns the provided username and password.

Jump to

Keyboard shortcuts

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