sftpd

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

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

Go to latest
Published: Mar 12, 2019 License: MIT Imports: 15 Imported by: 0

README

sftpd - SFTP server library in Go

License: MIT - Docs GoDoc

Recent changes - 2019

  • Attr.FillFrom cannot fail and now does not return an error value. Previously it was always nil.

FAQ

ssh: no common algorithms

The client and the server cannot agree on algorithms. Typically this is caused by an ECDSA host key. If using sshutil add the sshutil.RSA2048 flag.

Enabling debugging output

go build -tags debug -a

Will enable debugging output using package log.

TODO

  • Renames
  • Symlink creation

Documentation

Overview

Package sftpd is sftp (SSH File Transfer Protocol) server library.

Index

Constants

View Source
const (
	ATTR_SIZE    = ssh_FILEXFER_ATTR_SIZE
	ATTR_UIDGID  = ssh_FILEXFER_ATTR_UIDGID
	ATTR_MODE    = ssh_FILEXFER_ATTR_PERMISSIONS
	ATTR_TIME    = ssh_FILEXFER_ATTR_ACMODTIME
	MODE_REGULAR = os.FileMode(0)
	MODE_DIR     = os.ModeDir
)

Variables

View Source
var Failure = errors.New("Failure")

Functions

func IsSftpRequest

func IsSftpRequest(req *ssh.Request) bool

IsSftpRequest checks whether a given ssh.Request is for sftp.

func ServeChannel

func ServeChannel(c ssh.Channel, fs FileSystem) error

ServeChannel serves a ssh.Channel with the given FileSystem.

Types

type Attr

type Attr struct {
	Flags        uint32
	Size         uint64
	Uid, Gid     uint32
	User, Group  string
	Mode         os.FileMode
	ATime, MTime time.Time
	Extended     []string
}

func (*Attr) FillFrom

func (a *Attr) FillFrom(fi os.FileInfo)

FillFrom fills an Attr from a os.FileInfo

type Config

type Config struct {
	// ServerConfig should be initialized properly with
	// e.g. PasswordCallback and AddHostKey
	ssh.ServerConfig
	// HostPort specifies specifies [host]:port to listen on.
	// e.g. ":2022" or "127.0.0.1:2023".
	HostPort string
	// LogFunction is used to log errors.
	// e.g. log.Println has the right type.
	LogFunc func(v ...interface{})
	// FileSystem contains the FileSystem used for this server.
	FileSystem FileSystem
	// contains filtered or unexported fields
}

Config is the configuration struct for the high level API.

func (*Config) BlockTillReady

func (c *Config) BlockTillReady() error

BlockTillReady will block till the Config is ready to accept connections. Returns an error if listening failed. Can be called in a concurrent fashion. This is new API - make sure Init is called on the Config before using it.

func (*Config) Close

func (c *Config) Close() error

Close closes the server assosiated with this config. Can be called in a concurrent fashion. This is new API - make sure Init is called on the Config before using it.

func (*Config) Init

func (c *Config) Init()

Init inits a Config.

func (*Config) RunServer

func (c *Config) RunServer() error

RunServer runs the server using the high level API.

type Dir

type Dir interface {
	io.Closer
	Readdir(count int) ([]NamedAttr, error)
}

type EmptyFS

type EmptyFS struct{}
func (EmptyFS) CreateLink(p string, t string, f uint32) error

func (EmptyFS) Mkdir

func (EmptyFS) Mkdir(string, *Attr) error

func (EmptyFS) OpenDir

func (EmptyFS) OpenDir(string) (Dir, error)

func (EmptyFS) OpenFile

func (EmptyFS) OpenFile(string, uint32, *Attr) (File, error)
func (EmptyFS) ReadLink(p string) (string, error)

func (EmptyFS) RealPath

func (EmptyFS) RealPath(p string) (string, error)

func (EmptyFS) Remove

func (EmptyFS) Remove(string) error

func (EmptyFS) Rename

func (EmptyFS) Rename(string, string, uint32) error

func (EmptyFS) Rmdir

func (EmptyFS) Rmdir(string) error

func (EmptyFS) SetStat

func (EmptyFS) SetStat(string, *Attr) error

func (EmptyFS) Stat

func (EmptyFS) Stat(string, bool) (*Attr, error)

type EmptyFile

type EmptyFile struct{}

func (EmptyFile) Close

func (EmptyFile) Close() error

func (EmptyFile) FSetStat

func (EmptyFile) FSetStat(*Attr) error

func (EmptyFile) FStat

func (EmptyFile) FStat() (*Attr, error)

func (EmptyFile) ReadAt

func (EmptyFile) ReadAt([]byte, int64) (int, error)

func (EmptyFile) WriteAt

func (EmptyFile) WriteAt([]byte, int64) (int, error)

type File

type File interface {
	io.Closer
	io.ReaderAt
	io.WriterAt
	FStat() (*Attr, error)
	FSetStat(*Attr) error
}

type FileSystem

type FileSystem interface {
	OpenFile(name string, flags uint32, attr *Attr) (File, error)
	OpenDir(name string) (Dir, error)
	Remove(name string) error
	Rename(old string, new string, flags uint32) error
	Mkdir(name string, attr *Attr) error
	Rmdir(name string) error
	Stat(name string, islstat bool) (*Attr, error)
	SetStat(name string, attr *Attr) error
	ReadLink(path string) (string, error)
	CreateLink(path string, target string, flags uint32) error
	RealPath(path string) (string, error)
}

type NamedAttr

type NamedAttr struct {
	Name string
	Attr
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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