Add remove command
alex wennerberg alex@alexwennerberg.com
Fri, 26 Feb 2021 21:30:51 -0800
1 files changed,
12 insertions(+),
1 deletions(-)
jump to
M
sftp.go
→
sftp.go
@@ -74,8 +74,19 @@ }
return nil, fmt.Errorf("Invalid command") } -func (c *Connection) Filecmd(request *sftp.Request) error { +func (conn *Connection) Filecmd(request *sftp.Request) error { // remove, rename, setstat? find out + fullpath := path.Join(c.FilesDirectory, filepath.Clean(request.Filepath)) + userDir := getUserDirectory(conn.User) // NOTE -- not cross platform + writePerms := strings.HasPrefix(fullpath, userDir) + switch request.Method { + case "Remove": + if writePerms { + os.Remove(fullpath) + } else { + return fmt.Errorf("Unauthorized") + } + } return nil }