implement more commands
closes #9 closes #8 Signed-off-by: Vasiliy Tolstov <v.tolstov@selfip.ru>
This commit is contained in:
parent
cef2d33920
commit
76ed668b8d
63
main.go
63
main.go
@ -49,6 +49,8 @@ func handle(c net.Conn) {
|
|||||||
cmd := parts[0]
|
cmd := parts[0]
|
||||||
params := strings.Join(parts[1:], "")
|
params := strings.Join(parts[1:], "")
|
||||||
switch cmd {
|
switch cmd {
|
||||||
|
case "ABOR":
|
||||||
|
s.cmdServerAbor(params)
|
||||||
case "USER":
|
case "USER":
|
||||||
s.cmdServerUser(params)
|
s.cmdServerUser(params)
|
||||||
case "PASS":
|
case "PASS":
|
||||||
@ -91,10 +93,14 @@ func handle(c net.Conn) {
|
|||||||
s.cmdServerMkd(params)
|
s.cmdServerMkd(params)
|
||||||
case "RMD", "XRMD":
|
case "RMD", "XRMD":
|
||||||
s.cmdServerRmd(params)
|
s.cmdServerRmd(params)
|
||||||
|
case "AUTH":
|
||||||
|
s.cmdServerAuth(params)
|
||||||
case "STOR":
|
case "STOR":
|
||||||
s.cmdServerStor(params)
|
s.cmdServerStor(params)
|
||||||
case "SITE":
|
case "SITE":
|
||||||
s.cmdServerSite(params)
|
s.cmdServerSite(params)
|
||||||
|
case "NOOP":
|
||||||
|
s.cmdServerNoop(params)
|
||||||
default:
|
default:
|
||||||
fmt.Printf("%s\n", line)
|
fmt.Printf("%s\n", line)
|
||||||
}
|
}
|
||||||
@ -103,13 +109,13 @@ func handle(c net.Conn) {
|
|||||||
|
|
||||||
func (s *Conn) cmdServerUser(args string) {
|
func (s *Conn) cmdServerUser(args string) {
|
||||||
fmt.Printf("cmdServerUser: %s\n", args)
|
fmt.Printf("cmdServerUser: %s\n", args)
|
||||||
// s.user = args[0]
|
s.user = args
|
||||||
s.ctrl.PrintfLine("331 Password required for %s", args)
|
s.ctrl.PrintfLine("331 Password required for %s", args)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Conn) cmdServerPass(args string) {
|
func (s *Conn) cmdServerPass(args string) {
|
||||||
fmt.Printf("cmdServerPass: %s\n", args)
|
fmt.Printf("cmdServerPass: %s\n", args)
|
||||||
// s.token = args[0]
|
s.token = args
|
||||||
s.sw = &swift.Connection{UserName: s.user, ApiKey: s.token, AuthUrl: s.api, AuthVersion: 1}
|
s.sw = &swift.Connection{UserName: s.user, ApiKey: s.token, AuthUrl: s.api, AuthVersion: 1}
|
||||||
err := s.sw.Authenticate()
|
err := s.sw.Authenticate()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -152,13 +158,7 @@ func (s *Conn) cmdServerType(args string) {
|
|||||||
|
|
||||||
func (s *Conn) cmdServerList(args string) {
|
func (s *Conn) cmdServerList(args string) {
|
||||||
fmt.Printf("cmdServerList: %s\n", args)
|
fmt.Printf("cmdServerList: %s\n", args)
|
||||||
s.ctrl.PrintfLine(`150 Opening data channel for directory listing of "%s"`, args)
|
|
||||||
c, err := s.newSocket()
|
|
||||||
if err != nil {
|
|
||||||
fmt.Printf(err.Error())
|
|
||||||
s.ctrl.PrintfLine("425 Data connection failed")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
var files []os.FileInfo
|
var files []os.FileInfo
|
||||||
cnt := ""
|
cnt := ""
|
||||||
p := ""
|
p := ""
|
||||||
@ -186,7 +186,7 @@ func (s *Conn) cmdServerList(args string) {
|
|||||||
opts := &swift.ObjectsOpts{Delimiter: '/'}
|
opts := &swift.ObjectsOpts{Delimiter: '/'}
|
||||||
cnt = strings.Split(s.path, "/")[1]
|
cnt = strings.Split(s.path, "/")[1]
|
||||||
p = filepath.Clean(filepath.Join(strings.Join(strings.Split(s.path, "/")[2:], "/"), args))
|
p = filepath.Clean(filepath.Join(strings.Join(strings.Split(s.path, "/")[2:], "/"), args))
|
||||||
|
fmt.Printf("cnt: %s p: %s\n", cnt, p)
|
||||||
if p != "." {
|
if p != "." {
|
||||||
opts.Path = p
|
opts.Path = p
|
||||||
}
|
}
|
||||||
@ -195,7 +195,7 @@ func (s *Conn) cmdServerList(args string) {
|
|||||||
fmt.Printf(err.Error())
|
fmt.Printf(err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
fmt.Printf("%+v\n", objs)
|
||||||
files = append(files, NewDirItem(".", 4096, 0), NewDirItem("..", 4096, 0))
|
files = append(files, NewDirItem(".", 4096, 0), NewDirItem("..", 4096, 0))
|
||||||
var it os.FileInfo
|
var it os.FileInfo
|
||||||
|
|
||||||
@ -209,11 +209,22 @@ func (s *Conn) cmdServerList(args string) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
ls := newListFormatter(files)
|
ls := newListFormatter(files)
|
||||||
_, err = c.Write([]byte(ls.Detailed()))
|
s.ctrl.PrintfLine(`150 Opening data channel for directory listing of "%s"`, args)
|
||||||
|
c, err := s.newSocket()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf(err.Error())
|
fmt.Printf(err.Error())
|
||||||
|
s.ctrl.PrintfLine("425 Data connection failed")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
s.data = c
|
||||||
|
defer c.Close()
|
||||||
|
|
||||||
|
_, err = c.Write([]byte(ls.Detailed()))
|
||||||
|
if err != nil {
|
||||||
|
s.ctrl.PrintfLine("425 Data connection failed")
|
||||||
|
fmt.Printf(err.Error())
|
||||||
|
return
|
||||||
}
|
}
|
||||||
c.Close()
|
|
||||||
s.ctrl.PrintfLine(`226 Closing data connection`)
|
s.ctrl.PrintfLine(`226 Closing data connection`)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -247,6 +258,7 @@ func (s *Conn) cmdServerPasv(args string) {
|
|||||||
p1 := p0 / 256
|
p1 := p0 / 256
|
||||||
p2 := p0 - p1*256
|
p2 := p0 - p1*256
|
||||||
s.port, _ = strconv.Atoi(port)
|
s.port, _ = strconv.Atoi(port)
|
||||||
|
s.host = host
|
||||||
s.passive = true
|
s.passive = true
|
||||||
s.ctrl.PrintfLine("227 Entering Passive Mode (%s,%d,%d)", strings.Replace(host, ".", ",", -1), p1, p2)
|
s.ctrl.PrintfLine("227 Entering Passive Mode (%s,%d,%d)", strings.Replace(host, ".", ",", -1), p1, p2)
|
||||||
}
|
}
|
||||||
@ -269,7 +281,7 @@ func (s *Conn) newSocket() (net.Conn, error) {
|
|||||||
func (s *Conn) cmdServerSize(args string) {
|
func (s *Conn) cmdServerSize(args string) {
|
||||||
fmt.Printf("cmdServerSize: %s\n", args)
|
fmt.Printf("cmdServerSize: %s\n", args)
|
||||||
|
|
||||||
if s.path == "/" && len(args) == 0 {
|
if s.path == "/" && (len(args) == 0 || args == "/") {
|
||||||
s.ctrl.PrintfLine("213 %d", 0)
|
s.ctrl.PrintfLine("213 %d", 0)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -288,6 +300,7 @@ func (s *Conn) cmdServerSize(args string) {
|
|||||||
cnt = strings.Split(args, "/")[0]
|
cnt = strings.Split(args, "/")[0]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
fmt.Printf("cnt: %s p: %s\n", cnt, p)
|
||||||
if p != "" {
|
if p != "" {
|
||||||
obj, _, err := s.sw.Object(cnt, p)
|
obj, _, err := s.sw.Object(cnt, p)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -468,6 +481,7 @@ func (s *Conn) cmdServerRetr(args string) {
|
|||||||
s.ctrl.PrintfLine("425 Data connection failed")
|
s.ctrl.PrintfLine("425 Data connection failed")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
s.data = c
|
||||||
defer c.Close()
|
defer c.Close()
|
||||||
|
|
||||||
_, err = s.sw.ObjectGet(cnt, p, c, false, nil)
|
_, err = s.sw.ObjectGet(cnt, p, c, false, nil)
|
||||||
@ -499,6 +513,7 @@ func (s *Conn) cmdServerStor(args string) {
|
|||||||
s.ctrl.PrintfLine("425 Data connection failed")
|
s.ctrl.PrintfLine("425 Data connection failed")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
s.data = c
|
||||||
defer c.Close()
|
defer c.Close()
|
||||||
|
|
||||||
_, err = s.sw.ObjectPut(cnt, p, c, false, "", "", nil)
|
_, err = s.sw.ObjectPut(cnt, p, c, false, "", "", nil)
|
||||||
@ -514,3 +529,23 @@ func (s *Conn) cmdServerSite(args string) {
|
|||||||
s.ctrl.PrintfLine(`200 Success`)
|
s.ctrl.PrintfLine(`200 Success`)
|
||||||
//SITE CHMOD 0644 /public/.wgetpaste.conf
|
//SITE CHMOD 0644 /public/.wgetpaste.conf
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *Conn) cmdServerAuth(args string) {
|
||||||
|
switch args {
|
||||||
|
case "TLS":
|
||||||
|
s.ctrl.PrintfLine(`234 AUTH TLS successful`)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *Conn) cmdServerNoop(args string) {
|
||||||
|
s.ctrl.PrintfLine(`200 Success`)
|
||||||
|
//SITE CHMOD 0644 /public/.wgetpaste.conf
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *Conn) cmdServerAbor(args string) {
|
||||||
|
s.ctrl.PrintfLine(`426 Transfer abort`)
|
||||||
|
if s.data != nil {
|
||||||
|
s.data.Close()
|
||||||
|
}
|
||||||
|
s.ctrl.PrintfLine(`226 Closing data connection`)
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user