Documentation ¶
Index ¶
- Variables
- func ChangeDirectory(stack *StringStack, directory string) error
- func ChangeDirectoryCommand(c Client, directory string) error
- func ChangeDirectoryToPrevious(stack *StringStack) error
- func ClearScreen(c Client) error
- func GetFile(c Client, path string) (int64, error)
- func HandleConnection(client Client)
- func HandleUpload(conn net.Conn)
- func Init()
- func ListFiles(c Client) error
- func MakePathFromStringStack(stack *StringStack) string
- func ProcessInput(c Client, text string) error
- func SendASCIIPic(c Client, path string) error
- func ShowHelp(c Client) error
- func ShutdownFtpServer()
- func ShutdownUploadServer()
- func StartFtpServer(wg *sync.WaitGroup) error
- func StartUploadServer(wg *sync.WaitGroup) error
- func UploadFile(c Client, filename string) error
- type Client
- type FTPClient
- type InputError
- type PathError
- type Stack
- type StackError
- type StringStack
Constants ¶
This section is empty.
Variables ¶
var ( InputInvalidCommand = errors.New("invalid command") InputTooManyArguments = errors.New("too many arguments") InputTooFewArguments = errors.New("too few arguments") )
Input Errors
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
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
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!
var ConfigName string
ConfigName is used by the config package to find the config file.
var ConfigPath string
ConfigPath is used by the config package to find the path of the config file.
var (
ErrUploadServerFailure = errors.New("upload server failed to start")
)
General Errors
var (
GetNoBitsError = errors.New("the file/directory contains zero bits")
)
Command Errors represent errors that occur when the server is executing commands
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 ¶
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 ¶
ClearScreen cleans the client's screen by sending clear to the terminal.
func GetFile ¶
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 MakePathFromStringStack ¶
func MakePathFromStringStack(stack *StringStack) string
MakePathFromStringStack gets a StringStack and makes a path.
func ProcessInput ¶
func SendASCIIPic ¶
SendASCIIPic sends an image as ascii text to the client.
func ShutdownFtpServer ¶
func ShutdownFtpServer()
func ShutdownUploadServer ¶
func ShutdownUploadServer()
func StartFtpServer ¶
func StartUploadServer ¶
StartUploadServer starts the uploading server
func UploadFile ¶
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 ¶
Connection returns the Connection of the client.
func (*FTPClient) SetConnection ¶
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 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 ¶
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.