sftpfs

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2023 License: MIT Imports: 10 Imported by: 1

README

sftpfs Build

An SFTP client that implements fs.FS. It relies on the golang.org/x/crypto/ssh package for the underlying SSH implementation.

Requires Go 1.17 or newer.

Note that this can only be used to read files, as the fs.FS interface only supports reads. In the future this could be extended to support writes, but there currently aren't any plans for that.

Usage

Use the Dial method, like so:

c, err := sftpfs.Dial("tcp", "some-host-with-an-sftp-server.com:22", &ssh.ClientConfig{
	User: "username",
	Auth: []ssh.AuthMethod{
		ssh.Password("passw0rd"),
	},

	// InsecureIgnoreHostKey is unsafe!
	// You should probably use ssh.FixedHostKey.
	// See the golang.org/x/crypto/ssh documentation for details.
	HostKeyCallback: ssh.InsecureIgnoreHostKey(),
})
if err != nil {
	panic(err)
}
defer c.Close()

c is an *sftpfs.Client, which implements fs.FS. In other words, you can pass it directly to anything that uses an fs.FS, like fsbrowse.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

A Client is an SFTP client that implements fs.FS.

func Dial

func Dial(network, addr string, config *ssh.ClientConfig) (*Client, error)

Dial starts an SFTP connection with the given parameters.

func (*Client) Close

func (c *Client) Close() error

func (*Client) Open

func (c *Client) Open(name string) (fs.File, error)

func (*Client) ReadDir

func (c *Client) ReadDir(name string) ([]fs.DirEntry, error)

func (*Client) Request

func (c *Client) Request(packetType byte, payload interface{}) (interface{}, error)

type DirEntry

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

func (*DirEntry) Info

func (d *DirEntry) Info() (fs.FileInfo, error)

func (*DirEntry) IsDir

func (d *DirEntry) IsDir() bool

func (*DirEntry) Name

func (d *DirEntry) Name() string

func (*DirEntry) Type

func (d *DirEntry) Type() fs.FileMode

type File

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

func (*File) Close

func (f *File) Close() error

func (*File) Read

func (f *File) Read(buf []byte) (int, error)

func (*File) ReadDir

func (f *File) ReadDir(n int) ([]fs.DirEntry, error)

func (*File) Seek

func (f *File) Seek(offset int64, whence int) (int64, error)

func (*File) Stat

func (f *File) Stat() (fs.FileInfo, error)

type FileInfo

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

func (*FileInfo) IsDir

func (i *FileInfo) IsDir() bool

func (*FileInfo) ModTime

func (i *FileInfo) ModTime() time.Time

func (*FileInfo) Mode

func (i *FileInfo) Mode() fs.FileMode

func (*FileInfo) Name

func (i *FileInfo) Name() string

func (*FileInfo) Size

func (i *FileInfo) Size() int64

func (*FileInfo) Sys

func (i *FileInfo) Sys() interface{}

Jump to

Keyboard shortcuts

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