Documentation ¶
Overview ¶
Package sftpfs implements a SFTP client file system.
Index ¶
- Constants
- func AcceptAnyHostKey(hostname string, remote net.Addr, key ssh.PublicKey) error
- func Dial(ctx context.Context, address string, credentialsCallback CredentialsCallback, ...) (fs.FileSystem, error)
- func DialAndRegister(ctx context.Context, address string, credentialsCallback CredentialsCallback, ...) (fs.FileSystem, error)
- func EnsureRegistered(ctx context.Context, address string, credentialsCallback CredentialsCallback, ...) (free func() error, err error)
- type CredentialsCallback
Constants ¶
const ( Prefix = "sftp://" Separator = "/" )
Variables ¶
This section is empty.
Functions ¶
func AcceptAnyHostKey ¶
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 ¶
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.