sftpd

package module
v0.0.11 Latest Latest
Warning

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

Go to latest
Published: Dec 12, 2024 License: MIT Imports: 15 Imported by: 3

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, debugf DebugLogger) 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 BufferedReader added in v0.0.7

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

func (*BufferedReader) Close added in v0.0.7

func (b *BufferedReader) Close() error

func (*BufferedReader) Read added in v0.0.7

func (b *BufferedReader) Read(p []byte) (int, error)

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
	// ErrorLogFunc is used to log errors.
	// e.g. log.Println has the right type.
	ErrorLogFunc func(v ...interface{})
	// DebugLogFunc is used to log debug infos.
	// e.g. log.Printf has the right type.
	DebugLogFunc DebugLogger
}

Config is the configuration struct for the high level API.

type DebugLogger added in v0.0.10

type DebugLogger func(s string, v ...interface{})

type Dir

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

type DirReader added in v0.0.5

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

func (*DirReader) Close added in v0.0.5

func (d *DirReader) Close() error

func (*DirReader) Readdir added in v0.0.5

func (d *DirReader) 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.Reader
	io.Writer
	io.Seeker
	FStat() (*Attr, error)
	FSetStat(*Attr) error
}

type FileOpenArgs

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

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, 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 FileSystemExtensionFileList

type FileSystemExtensionFileList interface {
	// ReadDir reads the directory named by name and return a list of directory entries.
	ReadDir(name string) ([]NamedAttr, error)
}

FileSystemExtensionFileList is a convenience extension to allow to return file listing without requiring to implement the methods Open/Readdir for your custom afero.File From: github.com/fclairamb/ftpserverlib

type FileSystemExtentionFileTransfer

type FileSystemExtentionFileTransfer interface {
	// GetHandle return an handle to upload or download a file based on flags:
	// os.O_RDONLY indicates a download
	// os.O_WRONLY indicates an upload and can be combined with os.O_APPEND (resume) or
	// os.O_CREATE (upload to new file/truncate)
	//
	// offset is the argument of a previous REST command, if any, or 0
	GetHandle(name string, flags uint32, attr *Attr, offset uint64) (FileTransfer, error)
}

FileSystemExtentionFileTransfer is a convenience extension to allow to transfer files without requiring to implement the methods Create/Open/OpenFile for your custom afero.File. From: github.com/fclairamb/ftpserverlib

type FileTransfer

type FileTransfer interface {
	io.Reader
	io.Writer
	io.Closer
}

FileTransfer defines the inferface for file transfers. From: github.com/fclairamb/ftpserverlib

type NamedAttr

type NamedAttr struct {
	Name string
	Attr
}

type SftpDriver

type SftpDriver interface {
	GetConfig() *Config
	GetFileSystem(sc *ssh.ServerConn) (FileSystem, error)
	Close()
}

type SftpServer

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

func NewSftpServer

func NewSftpServer(driver SftpDriver) *SftpServer

NewSftpServer inits a SFTP Server.

func (*SftpServer) BlockTillReady

func (s *SftpServer) 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 (*SftpServer) Close

func (s *SftpServer) 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 (*SftpServer) LogError added in v0.0.10

func (s *SftpServer) LogError(v ...interface{})

func (*SftpServer) RunServer

func (s *SftpServer) RunServer() error

RunServer runs the server using the high level API.

Directories

Path Synopsis
The binp package provides parsing and printing of binary values.
The binp package provides parsing and printing of binary values.

Jump to

Keyboard shortcuts

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