server

package
v0.0.0-...-df4b14c Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2018 License: GPL-3.0 Imports: 20 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	InputInvalidCommand   = errors.New("invalid command")
	InputTooManyArguments = errors.New("too many arguments")
	InputTooFewArguments  = errors.New("too few arguments")
)

Input Errors

View Source
var (
	StackInvalidTypeError = StackError{"InvalidTypeError", errors.New("invalid item type for the Stack")}
	StackOverflowError    = StackError{"StackOverflowError", errors.New("stack capacity exceeded")}
	StackUnderflowError   = StackError{"StackUnderflowError", errors.New("stack is empty")}
	ErrStackCast          = StackError{"StackCastError", errors.New("stack can't be casted to selected type")}
)

Stack Errors

View Source
var (
	ErrInvalidDirectoryName   = PathError{errors.New("names should not contain / character")}
	ErrNotADirectory          = PathError{errors.New("file name is not a valid directory")}
	ErrAlreadyAtBaseDirectory = PathError{errors.New("can't go past beyond root directory")}
	ErrSlashNotAllowed        = PathError{errors.New("slash is not allowed in file names")}
)

PathErrors

View Source
var BasePath = ""

PATH is the constant which should contain the fixed path where the simpleFTP server will run This will act like a root cage. It must end with a forward slash!

View Source
var ConfigName string

ConfigName is used by the config package to find the config file.

View Source
var ConfigPath string

ConfigPath is used by the config package to find the path of the config file.

View Source
var (
	ErrUploadServerFailure = errors.New("upload server failed to start")
)

General Errors

View Source
var (
	GetNoBitsError = errors.New("the file/directory contains zero bits")
)

Command Errors represent errors that occur when the server is executing commands

View Source
var Shutdown = make(chan os.Signal)

Shutdown is the shutdown where SIGINT and SIGTERM is send too

Functions

func ChangeDirectory

func ChangeDirectory(stack *StringStack, directory string) error

ChangeDirectory changes the current working directory with respect to BasePath

func ChangeDirectoryCommand

func ChangeDirectoryCommand(c Client, directory string) error

ChangeDirectoryCommand changes the directory to the given directory

func ChangeDirectoryToPrevious

func ChangeDirectoryToPrevious(stack *StringStack) error

ChangeDirectoryToPrevious changes the current working directory to the previous one, doesn't go past the BasePath

func ClearScreen

func ClearScreen(c Client) error

ClearScreen cleans the client's screen by sending clear to the terminal.

func GetFile

func GetFile(c Client, path string) (int64, error)

GetFile sends the file to the client and returns true if it succeeds and false otherwise. it also returns the total number of send bytes.

func HandleConnection

func HandleConnection(client Client)

func HandleUpload

func HandleUpload(conn net.Conn)

func Init

func Init()

func ListFiles

func ListFiles(c Client) error

ListFiles list the files from path and sends them to the connection

func MakePathFromStringStack

func MakePathFromStringStack(stack *StringStack) string

MakePathFromStringStack gets a StringStack and makes a path.

func ProcessInput

func ProcessInput(c Client, text string) error

func SendASCIIPic

func SendASCIIPic(c Client, path string) error

SendASCIIPic sends an image as ascii text to the client.

func ShowHelp

func ShowHelp(c Client) error

ShowHelp writes the help text to the client.

func ShutdownFtpServer

func ShutdownFtpServer()

func ShutdownUploadServer

func ShutdownUploadServer()

func StartFtpServer

func StartFtpServer(wg *sync.WaitGroup) error

func StartUploadServer

func StartUploadServer(wg *sync.WaitGroup) error

StartUploadServer starts the uploading server

func UploadFile

func UploadFile(c Client, filename string) error

UploadFile uploads a file to the server

Types

type Client

type Client interface {
	Connection() net.Conn        // Connection returns the connection stream.
	SetConnection(conn net.Conn) // SetConnection sets the connection for the client.
	Disconnect()                 // Disconnect closes the Client's connections and clears up resources.
	Stack() *StringStack         // Returns the underlying String Stack.
}

Client interface provides the blueprints for the Client that is used by the server.

type FTPClient

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

FTPClient represents a FTPClient connection, it holds a root cage and the underlying connection.

func (*FTPClient) Connection

func (c *FTPClient) Connection() net.Conn

Connection returns the Connection of the client.

func (*FTPClient) Disconnect

func (c *FTPClient) Disconnect()

Disconnects the client.

func (*FTPClient) SetConnection

func (c *FTPClient) SetConnection(conn net.Conn)

SetConnection sets the given connection to the client.

func (*FTPClient) SetStack

func (c *FTPClient) SetStack(stack *StringStack)

SetStack sets the stack for the FTPClient.

func (*FTPClient) Stack

func (c *FTPClient) Stack() *StringStack

Stack returns the root cage stack.

type InputError

type InputError struct {
	// The operation that caused the error.
	Op string
	// The error that occurred during the operation.
	Err error
}

InputError will be raised when the input given to the parser by the client is not right.

func (InputError) Error

func (e InputError) Error() string

type PathError

type PathError struct {
	Err error
}

func (PathError) Error

func (e PathError) Error() string

type Stack

type Stack interface {
	// Push pushes an item to the stack. Returns an error if it fails.
	Push(item interface{})
	// Pop retrieves an item from the stack and removes it.
	Pop() interface{}
	// Top peeks at an item from the stack.
	Top() interface{}
	// IsEmpty returns bool indicating if the stack is empty.
	IsEmpty() bool
	// Capacity returns the capacity of the stack.
	Capacity() int
	// Size returns the size of the stack
	Size() int
}

Stack interface

type StackError

type StackError struct {
	ErrorName string
	Err       error
}

func (StackError) Error

func (e StackError) Error() string

type StringStack

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

StringStack is a stack that holds string objects

func MakeStringStack

func MakeStringStack(capacity int) *StringStack

MakeStringStack initializes a new StringStack pointer.

func (*StringStack) Capacity

func (st *StringStack) Capacity() int

Capacity returns the maximum items the stack can hold.

func (*StringStack) IsEmpty

func (st *StringStack) IsEmpty() bool

IsEmpty returns true if the stack contains no items.

func (StringStack) Items

func (st StringStack) Items() []string

Items returns an array of the stack items as a copy.

func (*StringStack) Pop

func (st *StringStack) Pop() interface{}

Pop returns the last pushed item from the stack and removes it

func (*StringStack) Push

func (st *StringStack) Push(item interface{})

Push pushes an item of type string to the stack.

func (*StringStack) Size

func (st *StringStack) Size() int

Size returns number of items the stack currently holds.

func (*StringStack) Top

func (st *StringStack) Top() interface{}

Top return the last pushed item from the stack without removing it.

Directories

Path Synopsis
This file contains the configuration settings for the server.
This file contains the configuration settings for the server.

Jump to

Keyboard shortcuts

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