-
Notifications
You must be signed in to change notification settings - Fork 31
/
ftpdriver.go
67 lines (54 loc) · 1.94 KB
/
ftpdriver.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package graval
import (
"io"
"os"
"time"
)
// For each client that connects to the server, a new FTPDriver is required.
// Create an implementation if this interface and provide it to FTPServer.
type FTPDriverFactory interface {
NewDriver() (FTPDriver, error)
}
// You will create an implementation of this interface that speaks to your
// chosen persistence layer. graval will create a new instance of your
// driver for each client that connects and delegate to it as required.
type FTPDriver interface {
// params - username, password
// returns - true if the provided details are valid
Authenticate(string, string) bool
// params - a file path
// returns - an int with the number of bytes in the file or -1 if the file
// doesn't exist
Bytes(string) int64
// params - a file path
// returns - a time indicating when the requested path was last modified
// - an error if the file doesn't exist or the user lacks
// permissions
ModifiedTime(string) (time.Time, error)
// params - path
// returns - true if the current user is permitted to change to the
// requested path
ChangeDir(string) bool
// params - path
// returns - a collection of items describing the contents of the requested
// path
DirContents(string) []os.FileInfo
// params - path
// returns - true if the directory was deleted
DeleteDir(string) bool
// params - path
// returns - true if the file was deleted
DeleteFile(string) bool
// params - from_path, to_path
// returns - true if the file was renamed
Rename(string, string) bool
// params - path
// returns - true if the new directory was created
MakeDir(string) bool
// params - path
// returns - a Reader that will return file data to send to the client
GetFile(string) (io.ReadCloser, error)
// params - desination path, an io.Reader containing the file data
// returns - true if the data was successfully persisted
PutFile(string, io.Reader) bool
}