minor fixes

Signed-off-by: Vasiliy Tolstov <v.tolstov@selfip.ru>
This commit is contained in:
Василий Толстов 2015-05-06 11:56:29 +03:00
parent 8547b51753
commit f848c36427

55
main.go
View File

@ -14,7 +14,7 @@ import (
) )
func main() { func main() {
l, err := net.Listen("tcp4", ":21") l, err := net.Listen("tcp4", "37.139.40.30:21")
if err != nil { if err != nil {
panic(err) panic(err)
@ -48,9 +48,15 @@ func handle(c net.Conn) {
return return
} }
parts := strings.Fields(line) parts := strings.Fields(line)
if len(parts) < 1 {
fmt.Printf("%s\n", line)
s.Close()
}
cmd := parts[0] cmd := parts[0]
params := strings.Join(parts[1:], "") params := strings.Join(parts[1:], "")
switch cmd { switch cmd {
case "OPTS":
s.cmdServerOpts(params)
case "MDTM": case "MDTM":
s.cmdServerMdtm(params) s.cmdServerMdtm(params)
case "ABOR": case "ABOR":
@ -109,6 +115,8 @@ func handle(c net.Conn) {
s.cmdServerNoop(params) s.cmdServerNoop(params)
default: default:
fmt.Printf("%s\n", line) fmt.Printf("%s\n", line)
s.Close()
return
} }
} }
} }
@ -141,7 +149,7 @@ func (s *Conn) cmdServerPwd(args string) {
func (s *Conn) cmdServerEpsv(args string) { func (s *Conn) cmdServerEpsv(args string) {
fmt.Printf("cmdServerEpsv: %s\n", args) fmt.Printf("cmdServerEpsv: %s\n", args)
if s.ln == nil { if s.ln == nil {
ln, err := net.Listen("tcp4", fmt.Sprintf(":%d", s.port)) ln, err := net.Listen("tcp4", fmt.Sprintf("37.139.40.30:%d", s.port))
if err != nil { if err != nil {
fmt.Printf(err.Error()) fmt.Printf(err.Error())
s.ctrl.PrintfLine("425 Data connection failed") s.ctrl.PrintfLine("425 Data connection failed")
@ -327,7 +335,7 @@ func (s *Conn) cmdServerQuit(args string) {
func (s *Conn) cmdServerPasv(args string) { func (s *Conn) cmdServerPasv(args string) {
fmt.Printf("cmdServerPasv: %s\n", args) fmt.Printf("cmdServerPasv: %s\n", args)
if s.ln == nil { if s.ln == nil {
ln, err := net.Listen("tcp4", fmt.Sprintf(":%d", s.port)) ln, err := net.Listen("tcp4", fmt.Sprintf("37.139.40.30:%d", s.port))
if err != nil { if err != nil {
fmt.Printf("%s\n", err.Error()) fmt.Printf("%s\n", err.Error())
s.ctrl.PrintfLine("425 Data connection failed") s.ctrl.PrintfLine("425 Data connection failed")
@ -418,6 +426,10 @@ func (s *Conn) cmdServerEprt(args string) {
s.ctrl.PrintfLine("200 Ok") s.ctrl.PrintfLine("200 Ok")
} }
func (s *Conn) cmdServerOpts(args string) {
s.ctrl.PrintfLine("200 Ok")
}
func (s *Conn) cmdServerLprt(args string) { func (s *Conn) cmdServerLprt(args string) {
fmt.Printf("cmdServerLprt: %s\n", args) fmt.Printf("cmdServerLprt: %s\n", args)
s.ctrl.PrintfLine("522 Data connection failed") s.ctrl.PrintfLine("522 Data connection failed")
@ -430,22 +442,23 @@ func (s *Conn) cmdServerLpsv(args string) {
func (s *Conn) cmdServerFeat(args string) { func (s *Conn) cmdServerFeat(args string) {
fmt.Printf("cmdServerFeat: %s\n", args) fmt.Printf("cmdServerFeat: %s\n", args)
s.ctrl.PrintfLine("501 Data connection failed") // s.ctrl.PrintfLine("501 Data connection failed")
return // return
s.ctrl.PrintfLine(`211-Extensions supported: s.ctrl.PrintfLine(`211-Extensions supported:
SIZE SIZE
RETR RETR
CWD CWD
PWD PWD
QUIT QUIT
SYST SYST
PASV PASV
EPSV EPSV
LIST LIST
TYPE TYPE
USER USER
PASS PASS
UTF8 UTF8
MDTM
211 END`) 211 END`)
} }
@ -486,9 +499,13 @@ func (s *Conn) cmdServerRmd(args string) {
if s.path != "/" { if s.path != "/" {
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))
} else {
cnt = strings.Split(args, "/")[0]
p = filepath.Clean(filepath.Join(s.path, strings.Join(strings.Split(args, "/")[1:], "/")))
} }
} }
if p != "" && p != "." { fmt.Printf("cnt %s p %s\n", cnt, p)
if p != "" && p != "." && p != "/" {
err = s.sw.ObjectDelete(cnt, p) err = s.sw.ObjectDelete(cnt, p)
} else { } else {
err = s.sw.ContainerDelete(cnt) err = s.sw.ContainerDelete(cnt)