kftpd

package module
v1.5.2 Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2023 License: MIT Imports: 20 Imported by: 0

README

kftpd

ftp server build in go

build

go build -o kftpd main/main.go

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ClientBeforePasv added in v1.4.1

func ClientBeforePasv(handler func(string) bool)

ClientBeforePasv register

func ClientBeforePort added in v1.4.1

func ClientBeforePort(handler func(string) bool)

ClientBeforePort register

func FileAfterDelete added in v0.8.0

func FileAfterDelete(handler func(string, string))

FileAfterDelete register

func FileAfterGet added in v0.8.0

func FileAfterGet(handler func(string, string))

FileAfterGet register

func FileAfterPut added in v0.8.0

func FileAfterPut(handler func(string, string))

FileAfterPut register

func FileAfterRename added in v0.8.0

func FileAfterRename(handler func(string, string, string))

FileAfterRename register

func FileBeforeDelete added in v0.8.0

func FileBeforeDelete(handler func(string, string) bool)

FileBeforeDelete register

func FileBeforeGet added in v0.8.0

func FileBeforeGet(handler func(string, string) bool)

FileBeforeGet register

func FileBeforePut added in v0.8.0

func FileBeforePut(handler func(string, string) bool)

FileBeforePut register

func FileBeforeRename added in v0.8.0

func FileBeforeRename(handler func(string, string, string) bool)

FileBeforeRename register

func FtpdServe added in v0.0.3

func FtpdServe(config *FtpdConfig) error

FtpdServe start the ftp server

func SetDriverFactory added in v1.0.0

func SetDriverFactory(customDriverFactory DriverFactory)

SetDriverFactory set a custom ftp driver factory

func UserAfterLogin added in v0.8.0

func UserAfterLogin(handler func(string))

UserAfterLogin register

func UserBeforeLogin added in v0.8.0

func UserBeforeLogin(handler func(string, string) bool)

UserBeforeLogin register

Types

type Driver

type Driver interface {
	Stat(string) (FileInfo, error)

	Chtimes(string, time.Time, time.Time) error

	DeleteDir(string) error

	DeleteFile(string) error

	Rename(string, string) error

	MakeDir(string) error

	ListDir(string, func(FileInfo) error) error

	GetFile(string, int64) (int64, io.ReadCloser, error)

	PutFile(string, int64, io.Reader) (int64, error)
}

Driver - file driver interface

type DriverFactory

type DriverFactory interface {
	NewDriver(string) (Driver, error)
}

DriverFactory - new a driver

func NewFileDriverFactory

func NewFileDriverFactory(root string) DriverFactory

NewFileDriverFactory return a file based driver factory

func NewMinioDriverFactory

func NewMinioDriverFactory(endpoint, accessKeyID, secretAccessKey, bucket string, useSSL bool) DriverFactory

NewMinioDriverFactory return a minio driver factory

type FileDriver

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

FileDriver - file based driver

func (*FileDriver) Chtimes

func (driver *FileDriver) Chtimes(path string, atime time.Time, mtime time.Time) error

Chtimes change file modify time

func (*FileDriver) DeleteDir

func (driver *FileDriver) DeleteDir(path string) error

DeleteDir delete a dir

func (*FileDriver) DeleteFile

func (driver *FileDriver) DeleteFile(path string) error

DeleteFile delete a file

func (*FileDriver) GetFile

func (driver *FileDriver) GetFile(path string, offset int64) (int64, io.ReadCloser, error)

GetFile return file size, file reader

func (*FileDriver) ListDir

func (driver *FileDriver) ListDir(path string, callback func(FileInfo) error) error

ListDir return file list in dir

func (*FileDriver) MakeDir

func (driver *FileDriver) MakeDir(path string) error

MakeDir make a dir

func (*FileDriver) PutFile

func (driver *FileDriver) PutFile(path string, offset int64, reader io.Reader) (int64, error)

PutFile put a file, support append with offset.

func (*FileDriver) Rename

func (driver *FileDriver) Rename(from string, to string) error

Rename rename a file or dir

func (*FileDriver) Stat

func (driver *FileDriver) Stat(path string) (FileInfo, error)

Stat return file information

type FileDriverFactory

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

FileDriverFactory - file based driver factory

func (*FileDriverFactory) NewDriver

func (factory *FileDriverFactory) NewDriver(user string) (Driver, error)

NewDriver return a file based driver

type FileInfo

type FileInfo interface {
	os.FileInfo
}

FileInfo - ftp file information

type FtpCmd

type FtpCmd struct {
	Fn   func(*FtpConn) error
	Auth bool
}

FtpCmd - ftp command handler

type FtpConn

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

FtpConn - ftp session

func NewFtpConn

func NewFtpConn(cid int, conn net.Conn, config *FtpdConfig, tlsConfig *tls.Config, factory DriverFactory) *FtpConn

NewFtpConn return a new ftp session

func (*FtpConn) Close

func (fc *FtpConn) Close()

Close close ftp connections

func (*FtpConn) CloseFileTransfer

func (fc *FtpConn) CloseFileTransfer()

CloseFileTransfer close a ftp file transfer

func (*FtpConn) GetFileTransfer

func (fc *FtpConn) GetFileTransfer() io.Reader

GetFileTransfer return a client file reader transfer

func (*FtpConn) OpenFileTransfer

func (fc *FtpConn) OpenFileTransfer(conn net.Conn)

OpenFileTransfer open a ftp file transfer

func (*FtpConn) PutFileTransfer

func (fc *FtpConn) PutFileTransfer(reader io.Reader) error

PutFileTransfer transfer a ftp file to client

func (*FtpConn) Send

func (fc *FtpConn) Send(code int, msg string)

Send send code and message to client

func (*FtpConn) SendMulti

func (fc *FtpConn) SendMulti(code int, header, body, footer string)

SendMulti send code and multiple line message to client

func (*FtpConn) Serve

func (fc *FtpConn) Serve()

Serve parse and handle ftp client data

func (*FtpConn) WriteFileTransfer

func (fc *FtpConn) WriteFileTransfer(msg []byte)

WriteFileTransfer write data to file transfer

type FtpdConfig

type FtpdConfig struct {
	Bind    string `yaml:"Bind,omitempty"`
	Driver  string `yaml:"Driver,omitempty"`
	HomeDir bool   `yaml:"HomeDir,omitempty"`
	Debug   bool   `yaml:"Debug,omitempty"`

	Pasv struct {
		Enable        bool   `yaml:"Enable,omitempty"`
		IP            string `yaml:"IP,omitempty"`
		PortStart     int    `yaml:"PortStart,omitempty"`
		PortEnd       int    `yaml:"PortEnd,omitempty"`
		ListenTimeout int    `yaml:"ListenTimeout,omitempty"`
	} `yaml:"Pasv,omitempty"`

	Port struct {
		Enable         bool `yaml:"Enable,omitempty"`
		ConnectTimeout int  `yaml:"ConnectTimeout,omitempty"`
	} `yaml:"Port,omitempty"`

	FileDriver struct {
		BaseDir string `yaml:"BaseDir,omitempty"`
	} `yaml:"FileDriver,omitempty"`

	MinioDriver struct {
		Endpoint        string `yaml:"Endpoint,omitempty"`
		AccessKeyID     string `yaml:"AccessKeyID,omitempty"`
		SecretAccessKey string `yaml:"SecretAccessKey,omitempty"`
		UseSSL          bool   `yaml:"UseSSL,omitempty"`
		Bucket          string `yaml:"Bucket,omitempty"`
	} `yaml:"MinioDriver,omitempty"`

	AuthTLS struct {
		Enable   bool   `yaml:"Enable,omitempty"`
		CertFile string `yaml:"CertFile,omitempty"`
		KeyFile  string `yaml:"KeyFile,omitempty"`
	} `yaml:"AuthTLS,omitempty"`

	Users map[string]string `yaml:"Users,omitempty"`
}

FtpdConfig - ftpd configure

func LoadFtpdConfig added in v0.4.0

func LoadFtpdConfig(configFile string) (*FtpdConfig, error)

LoadFtpdConfig return a ftd config loaded from config file

func NewFtpdConfig

func NewFtpdConfig() *FtpdConfig

NewFtpdConfig return a ftd config

type FtpdHandler added in v0.8.0

type FtpdHandler struct {
	UserBeforeLogin func(string, string) bool
	UserAfterLogin  func(string)

	ClientBeforePasv func(string) bool
	ClientBeforePort func(string) bool

	FileBeforePut func(string, string) bool
	FileAfterPut  func(string, string)

	FileBeforeGet func(string, string) bool
	FileAfterGet  func(string, string)

	FileBeforeDelete func(string, string) bool
	FileAfterDelete  func(string, string)

	FileBeforeRename func(string, string, string) bool
	FileAfterRename  func(string, string, string)
}

FtpdHandler - ftpd handler

type MinioDriver

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

MinioDriver - minio driver

func (*MinioDriver) Chtimes

func (driver *MinioDriver) Chtimes(path string, atime time.Time, mtime time.Time) error

Chtimes change file modify time

func (*MinioDriver) DeleteDir

func (driver *MinioDriver) DeleteDir(path string) error

DeleteDir delete dir in minio

func (*MinioDriver) DeleteFile

func (driver *MinioDriver) DeleteFile(path string) error

DeleteFile delete file in minio

func (*MinioDriver) GetFile

func (driver *MinioDriver) GetFile(path string, offset int64) (int64, io.ReadCloser, error)

GetFile return file size, file reader in minio

func (*MinioDriver) ListDir

func (driver *MinioDriver) ListDir(path string, callback func(FileInfo) error) error

ListDir return file list from dir in minio

func (*MinioDriver) MakeDir

func (driver *MinioDriver) MakeDir(path string) error

MakeDir make dir in minio

func (*MinioDriver) PutFile

func (driver *MinioDriver) PutFile(path string, offset int64, reader io.Reader) (int64, error)

PutFile put a file to minio, support append with offset.

func (*MinioDriver) Rename

func (driver *MinioDriver) Rename(from string, to string) error

Rename rename file or dir in minio

func (*MinioDriver) Stat

func (driver *MinioDriver) Stat(path string) (FileInfo, error)

Stat return file information

type MinioDriverFactory

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

MinioDriverFactory - minio driver factory

func (*MinioDriverFactory) NewDriver

func (factory *MinioDriverFactory) NewDriver(user string) (Driver, error)

NewDriver return a minio driver

type MinioFileInfo

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

MinioFileInfo - minio file information

func (*MinioFileInfo) IsDir

func (m *MinioFileInfo) IsDir() bool

IsDir return minio path is dir

func (*MinioFileInfo) ModTime

func (m *MinioFileInfo) ModTime() time.Time

ModTime return minio file modify time

func (*MinioFileInfo) Mode

func (m *MinioFileInfo) Mode() os.FileMode

Mode return minio file mode

func (*MinioFileInfo) Name

func (m *MinioFileInfo) Name() string

Name return minio file name

func (*MinioFileInfo) Size

func (m *MinioFileInfo) Size() int64

Size return minio file size

func (*MinioFileInfo) Sys

func (m *MinioFileInfo) Sys() interface{}

Sys return minio file system information, not implemented.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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