scp

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2024 License: MIT Imports: 15 Imported by: 9

Documentation

Overview

Package scp provides a SCP middleware for wish.

Index

Constants

This section is empty.

Variables

View Source
var NULL = []byte{'\x00'}

NULL is an array with a single NULL byte.

Functions

func Middleware

Middleware provides a wish middleware using the given CopyToClientHandler and CopyFromClientHandler.

Types

type AppendableEntry

type AppendableEntry interface {
	// Write the current entry in SCP format.
	Write(io.Writer) error

	// Append another entry to the current entry.
	Append(entry Entry)
}

AppendableEntry defines a special kind of Entry, which can contain children.

type CopyFromClientHandler

type CopyFromClientHandler interface {
	// Mkdir should created the given dir.
	// Note that this usually shouldn't use os.MkdirAll and the like.
	Mkdir(ssh.Session, *DirEntry) error

	// Write should write the given file.
	Write(ssh.Session, *FileEntry) (int64, error)
}

CopyFromClientHandler is a handler that can be implemented to handle files being copied from the client to the server.

type CopyToClientHandler

type CopyToClientHandler interface {
	// Glob should be implemented if you want to provide server-side globbing
	// support.
	//
	// A minimal implementation to disable it is to return `[]string{s}, nil`.
	//
	// Note: if your other functions expect a relative path, make sure that
	// your Glob implementation returns relative paths as well.
	Glob(ssh.Session, string) ([]string, error)

	// WalkDir must be implemented if you want to allow recursive copies.
	WalkDir(ssh.Session, string, fs.WalkDirFunc) error

	// NewDirEntry should provide a *DirEntry for the given path.
	NewDirEntry(ssh.Session, string) (*DirEntry, error)

	// NewFileEntry should provide a *FileEntry for the given path.
	// Users may also provide a closing function.
	NewFileEntry(ssh.Session, string) (*FileEntry, func() error, error)
}

CopyToClientHandler is a handler that can be implemented to handle files being copied from the server to the client.

func NewFSReadHandler

func NewFSReadHandler(fsys fs.FS) CopyToClientHandler

NewFSReadHandler returns a read-only CopyToClientHandler that accepts any fs.FS as input.

type DirEntry

type DirEntry struct {
	Children []Entry
	Name     string
	Filepath string
	Mode     fs.FileMode
	Atime    int64
	Mtime    int64
}

DirEntry is an Entry with mode, possibly children, and possibly a parent.

func (*DirEntry) Append

func (e *DirEntry) Append(entry Entry)

Appends an entry to the folder or their children.

func (*DirEntry) Write

func (e *DirEntry) Write(w io.Writer) error

Write the current dir entry, all its contents (recursively), and the dir closing to the given writer.

type Entry

type Entry interface {
	// Write the current entry in SCP format.
	Write(io.Writer) error
	// contains filtered or unexported methods
}

Entry defines something that knows how to write itself and its path.

type FileEntry

type FileEntry struct {
	Name     string
	Filepath string
	Mode     fs.FileMode
	Size     int64
	Reader   io.Reader
	Atime    int64
	Mtime    int64
}

FileEntry is an Entry that reads from a Reader, defining a file and its contents.

func (*FileEntry) Write

func (e *FileEntry) Write(w io.Writer) error

Write a file to the given writer.

type Handler

type Handler interface {
	CopyFromClientHandler
	CopyToClientHandler
}

Handler is a interface that can be implemented to handle both SCP directions.

func NewFileSystemHandler

func NewFileSystemHandler(root string) Handler

NewFileSystemHandler return a Handler based on the given dir.

type Info

type Info struct {
	// Ok is true if the current session is a SCP.
	Ok bool

	// Recursive is true if its a recursive SCP.
	Recursive bool

	// Path is the server path of the scp operation.
	Path string

	// Op is the SCP operation kind.
	Op Op
}

Info provides some information about the current SCP Operation.

func GetInfo

func GetInfo(cmd []string) Info

GetInfo return information about the given command.

type Op

type Op byte

Op defines which kind of SCP Operation is going on.

const (
	// OpCopyToClient is when a file is being copied from the server to the client.
	OpCopyToClient Op = 'f'

	// OpCopyFromClient is when a file is being copied from the client into the server.
	OpCopyFromClient Op = 't'
)

type RootEntry

type RootEntry []Entry

RootEntry is a root entry that can only have children.

func (*RootEntry) Append

func (e *RootEntry) Append(entry Entry)

Appennd the given entry to a child directory, or the the itself if none matches.

func (*RootEntry) Write

func (e *RootEntry) Write(w io.Writer) error

Write recursively writes all the children to the given writer.

Jump to

Keyboard shortcuts

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