protosftp

package
v0.0.0-...-57e3cb4 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2019 License: MIT, BSD-2-Clause Imports: 5 Imported by: 0

README

This package is a derivative of https://github.com/pkg/sftp

It was modified to strip the purely functional protocol specific aspects of the protocol out, which let me focus on fixing other issues I had with that package, such as out of order packet processing.

Documentation

Index

Constants

View Source
const (
	FXP_INIT           = 1
	FXP_VERSION        = 2
	FXP_OPEN           = 3
	FXP_CLOSE          = 4
	FXP_READ           = 5
	FXP_WRITE          = 6
	FXP_LSTAT          = 7
	FXP_FSTAT          = 8
	FXP_SETSTAT        = 9
	FXP_FSETSTAT       = 10
	FXP_OPENDIR        = 11
	FXP_READDIR        = 12
	FXP_REMOVE         = 13
	FXP_MKDIR          = 14
	FXP_RMDIR          = 15
	FXP_REALPATH       = 16
	FXP_STAT           = 17
	FXP_RENAME         = 18
	FXP_READLINK       = 19
	FXP_SYMLINK        = 20
	FXP_STATUS         = 101
	FXP_HANDLE         = 102
	FXP_DATA           = 103
	FXP_NAME           = 104
	FXP_ATTRS          = 105
	FXP_EXTENDED       = 200
	FXP_EXTENDED_REPLY = 201
)
View Source
const (
	FX_OK                = 0
	FX_EOF               = 1
	FX_NO_SUCH_FILE      = 2
	FX_PERMISSION_DENIED = 3
	FX_FAILURE           = 4
	FX_BAD_MESSAGE       = 5
	FX_NO_CONNECTION     = 6
	FX_CONNECTION_LOST   = 7
	FX_OP_UNSUPPORTED    = 8

	// see draft-ietf-secsh-filexfer-13
	// https://tools.ietf.org/html/draft-ietf-secsh-filexfer-13#section-9.1
	FX_INVALID_HANDLE              = 9
	FX_NO_SUCH_PATH                = 10
	FX_FILE_ALREADY_EXISTS         = 11
	FX_WRITE_PROTECT               = 12
	FX_NO_MEDIA                    = 13
	FX_NO_SPACE_ON_FILESYSTEM      = 14
	FX_QUOTA_EXCEEDED              = 15
	FX_UNKNOWN_PRINCIPAL           = 16
	FX_LOCK_CONFLICT               = 17
	FX_DIR_NOT_EMPTY               = 18
	FX_NOT_A_DIRECTORY             = 19
	FX_INVALID_FILENAME            = 20
	FX_LINK_LOOP                   = 21
	FX_CANNOT_DELETE               = 22
	FX_INVALID_PARAMETER           = 23
	FX_FILE_IS_A_DIRECTORY         = 24
	FX_BYTE_RANGE_LOCK_CONFLICT    = 25
	FX_BYTE_RANGE_LOCK_REFUSED     = 26
	FX_DELETE_PENDING              = 27
	FX_FILE_CORRUPT                = 28
	FX_OWNER_INVALID               = 29
	FX_GROUP_INVALID               = 30
	FX_NO_MATCHING_BYTE_RANGE_LOCK = 31
)
View Source
const (
	FXF_READ   = 0x00000001
	FXF_WRITE  = 0x00000002
	FXF_APPEND = 0x00000004
	FXF_CREAT  = 0x00000008
	FXF_TRUNC  = 0x00000010
	FXF_EXCL   = 0x00000020
)
View Source
const (
	FILEXFER_ATTR_SIZE        = 0x00000001
	FILEXFER_ATTR_UIDGID      = 0x00000002
	FILEXFER_ATTR_PERMISSIONS = 0x00000004
	FILEXFER_ATTR_ACMODTIME   = 0x00000008
	FILEXFER_ATTR_EXTENDED    = 0x80000000
)
View Source
const (
	S_IFMT   = 00170000
	S_IFSOCK = 0140000
	S_IFLNK  = 0120000
	S_IFREG  = 0100000
	S_IFBLK  = 0060000
	S_IFDIR  = 0040000
	S_IFCHR  = 0020000
	S_IFIFO  = 0010000
	S_ISUID  = 0004000
	S_ISGID  = 0002000
	S_ISVTX  = 0001000
)
View Source
const ProtocolVersion = 3

Variables

View Source
var EmptyFileStat = FileStat{}

Functions

func WritePacket

func WritePacket(w io.Writer, m Packet) error

Types

type FileStat

type FileStat struct {
	Flags    uint32
	Size     uint64
	Mode     uint32
	Mtime    uint32
	Atime    uint32
	UID      uint32
	GID      uint32
	Extended []StatExtended
}

type FxVersionPacket

type FxVersionPacket struct {
	Version    uint32
	Extensions []struct {
		Name, Data string
	}
}

func (FxVersionPacket) MarshalBinary

func (p FxVersionPacket) MarshalBinary() ([]byte, error)

func (FxVersionPacket) UnmarshalBinary

func (p FxVersionPacket) UnmarshalBinary(b []byte) error

type FxpClosePacket

type FxpClosePacket struct {
	ID     uint32
	Handle string
}

func (FxpClosePacket) MarshalBinary

func (p FxpClosePacket) MarshalBinary() ([]byte, error)

func (*FxpClosePacket) UnmarshalBinary

func (p *FxpClosePacket) UnmarshalBinary(b []byte) error

type FxpDataPacket

type FxpDataPacket struct {
	ID     uint32
	Length uint32
	Data   []byte
}

func (FxpDataPacket) MarshalBinary

func (p FxpDataPacket) MarshalBinary() ([]byte, error)

func (*FxpDataPacket) UnmarshalBinary

func (p *FxpDataPacket) UnmarshalBinary(b []byte) error

type FxpFSetStatPacket

type FxpFSetStatPacket struct {
	ID     uint32
	Handle string
	Attrs  FileStat
}

func (FxpFSetStatPacket) MarshalBinary

func (p FxpFSetStatPacket) MarshalBinary() ([]byte, error)

func (*FxpFSetStatPacket) UnmarshalBinary

func (p *FxpFSetStatPacket) UnmarshalBinary(b []byte) error

type FxpFstatPacket

type FxpFstatPacket struct {
	ID     uint32
	Handle string
}

func (FxpFstatPacket) MarshalBinary

func (p FxpFstatPacket) MarshalBinary() ([]byte, error)

func (*FxpFstatPacket) UnmarshalBinary

func (p *FxpFstatPacket) UnmarshalBinary(b []byte) error

type FxpHandlePacket

type FxpHandlePacket struct {
	ID     uint32
	Handle string
}

func (FxpHandlePacket) MarshalBinary

func (p FxpHandlePacket) MarshalBinary() ([]byte, error)

func (*FxpHandlePacket) UnmarshalBinary

func (p *FxpHandlePacket) UnmarshalBinary(b []byte) error

type FxpInitPacket

type FxpInitPacket struct {
	Version    uint32
	Extensions []extensionPair
}

func (FxpInitPacket) MarshalBinary

func (p FxpInitPacket) MarshalBinary() ([]byte, error)

func (*FxpInitPacket) UnmarshalBinary

func (p *FxpInitPacket) UnmarshalBinary(b []byte) error

type FxpLstatPacket

type FxpLstatPacket struct {
	ID   uint32
	Path string
}

func (FxpLstatPacket) MarshalBinary

func (p FxpLstatPacket) MarshalBinary() ([]byte, error)

func (*FxpLstatPacket) UnmarshalBinary

func (p *FxpLstatPacket) UnmarshalBinary(b []byte) error

type FxpMkdirPacket

type FxpMkdirPacket struct {
	ID    uint32
	Path  string
	Attrs FileStat
}

func (FxpMkdirPacket) MarshalBinary

func (p FxpMkdirPacket) MarshalBinary() ([]byte, error)

func (*FxpMkdirPacket) UnmarshalBinary

func (p *FxpMkdirPacket) UnmarshalBinary(b []byte) error

type FxpNameAttr

type FxpNameAttr struct {
	Name     string
	LongName string
	Attrs    FileStat
}

func (FxpNameAttr) MarshalBinary

func (p FxpNameAttr) MarshalBinary() ([]byte, error)

type FxpNamePacket

type FxpNamePacket struct {
	ID        uint32
	NameAttrs []FxpNameAttr
}

func (FxpNamePacket) MarshalBinary

func (p FxpNamePacket) MarshalBinary() ([]byte, error)

func (FxpNamePacket) UnmarshalBinary

func (p FxpNamePacket) UnmarshalBinary(b []byte) error

type FxpOpenPacket

type FxpOpenPacket struct {
	ID     uint32
	Path   string
	Pflags uint32
	Attrs  FileStat
}

func (FxpOpenPacket) MarshalBinary

func (p FxpOpenPacket) MarshalBinary() ([]byte, error)

func (*FxpOpenPacket) UnmarshalBinary

func (p *FxpOpenPacket) UnmarshalBinary(b []byte) error

type FxpOpendirPacket

type FxpOpendirPacket struct {
	ID   uint32
	Path string
}

func (FxpOpendirPacket) MarshalBinary

func (p FxpOpendirPacket) MarshalBinary() ([]byte, error)

func (*FxpOpendirPacket) UnmarshalBinary

func (p *FxpOpendirPacket) UnmarshalBinary(b []byte) error

type FxpReadPacket

type FxpReadPacket struct {
	ID     uint32
	Handle string
	Offset uint64
	Len    uint32
}

func (FxpReadPacket) MarshalBinary

func (p FxpReadPacket) MarshalBinary() ([]byte, error)

func (*FxpReadPacket) UnmarshalBinary

func (p *FxpReadPacket) UnmarshalBinary(b []byte) error

type FxpReaddirPacket

type FxpReaddirPacket struct {
	ID     uint32
	Handle string
}

func (FxpReaddirPacket) MarshalBinary

func (p FxpReaddirPacket) MarshalBinary() ([]byte, error)

func (*FxpReaddirPacket) UnmarshalBinary

func (p *FxpReaddirPacket) UnmarshalBinary(b []byte) error

type FxpReadlinkPacket

type FxpReadlinkPacket struct {
	ID   uint32
	Path string
}

func (FxpReadlinkPacket) MarshalBinary

func (p FxpReadlinkPacket) MarshalBinary() ([]byte, error)

func (*FxpReadlinkPacket) UnmarshalBinary

func (p *FxpReadlinkPacket) UnmarshalBinary(b []byte) error

type FxpRealpathPacket

type FxpRealpathPacket struct {
	ID   uint32
	Path string
}

func (FxpRealpathPacket) MarshalBinary

func (p FxpRealpathPacket) MarshalBinary() ([]byte, error)

func (*FxpRealpathPacket) UnmarshalBinary

func (p *FxpRealpathPacket) UnmarshalBinary(b []byte) error

type FxpRemovePacket

type FxpRemovePacket struct {
	ID       uint32
	Filename string
}

func (FxpRemovePacket) MarshalBinary

func (p FxpRemovePacket) MarshalBinary() ([]byte, error)

func (*FxpRemovePacket) UnmarshalBinary

func (p *FxpRemovePacket) UnmarshalBinary(b []byte) error

type FxpRenamePacket

type FxpRenamePacket struct {
	ID      uint32
	Oldpath string
	Newpath string
}

func (FxpRenamePacket) MarshalBinary

func (p FxpRenamePacket) MarshalBinary() ([]byte, error)

func (*FxpRenamePacket) UnmarshalBinary

func (p *FxpRenamePacket) UnmarshalBinary(b []byte) error

type FxpRmdirPacket

type FxpRmdirPacket struct {
	ID   uint32
	Path string
}

func (FxpRmdirPacket) MarshalBinary

func (p FxpRmdirPacket) MarshalBinary() ([]byte, error)

func (*FxpRmdirPacket) UnmarshalBinary

func (p *FxpRmdirPacket) UnmarshalBinary(b []byte) error

type FxpSetStatPacket

type FxpSetStatPacket struct {
	ID    uint32
	Path  string
	Attrs FileStat
}

func (FxpSetStatPacket) MarshalBinary

func (p FxpSetStatPacket) MarshalBinary() ([]byte, error)

func (*FxpSetStatPacket) UnmarshalBinary

func (p *FxpSetStatPacket) UnmarshalBinary(b []byte) error

type FxpStatPacket

type FxpStatPacket struct {
	ID   uint32
	Path string
}

func (FxpStatPacket) MarshalBinary

func (p FxpStatPacket) MarshalBinary() ([]byte, error)

func (*FxpStatPacket) UnmarshalBinary

func (p *FxpStatPacket) UnmarshalBinary(b []byte) error

type FxpStatResponse

type FxpStatResponse struct {
	ID   uint32
	Info FileStat
}

func (FxpStatResponse) MarshalBinary

func (p FxpStatResponse) MarshalBinary() ([]byte, error)

func (FxpStatResponse) UnmarshalBinary

func (p FxpStatResponse) UnmarshalBinary(b []byte) error

type FxpStatusPacket

type FxpStatusPacket struct {
	ID          uint32
	StatusError StatusError
}

func MakeStatus

func MakeStatus(id uint32, msg string, code uint32) *FxpStatusPacket

func (FxpStatusPacket) MarshalBinary

func (p FxpStatusPacket) MarshalBinary() ([]byte, error)

func (FxpStatusPacket) UnmarshalBinary

func (p FxpStatusPacket) UnmarshalBinary(b []byte) error

type FxpSymlinkPacket

type FxpSymlinkPacket struct {
	ID         uint32
	Targetpath string
	Linkpath   string
}

func (FxpSymlinkPacket) MarshalBinary

func (p FxpSymlinkPacket) MarshalBinary() ([]byte, error)

func (*FxpSymlinkPacket) UnmarshalBinary

func (p *FxpSymlinkPacket) UnmarshalBinary(b []byte) error

type FxpWritePacket

type FxpWritePacket struct {
	ID     uint32
	Handle string
	Offset uint64
	Length uint32
	Data   []byte
}

func (FxpWritePacket) MarshalBinary

func (p FxpWritePacket) MarshalBinary() ([]byte, error)

func (*FxpWritePacket) UnmarshalBinary

func (p *FxpWritePacket) UnmarshalBinary(b []byte) error

type Packet

func ReadPacket

func ReadPacket(r io.Reader) (Packet, error)

type StatExtended

type StatExtended struct {
	ExtType string
	ExtData string
}

type StatusError

type StatusError struct {
	Code uint32
	Msg  string
	Lang string
}

A StatusError is returned when an SFTP operation fails, and provides additional information about the failure.

func (*StatusError) Error

func (s *StatusError) Error() string

Jump to

Keyboard shortcuts

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