From eec673f6402f81778dfc03cd215aa3aa6e86f281 Mon Sep 17 00:00:00 2001 From: ren yuze Date: Fri, 6 Sep 2019 10:26:03 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dwindows=E5=90=91Linux?= =?UTF-8?q?=E4=BC=A0=E8=BE=93=E5=8F=91=E7=94=9F=E6=96=87=E4=BB=B6=E5=A4=B9?= =?UTF-8?q?=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- vtqe/tools/tcp.go | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/vtqe/tools/tcp.go b/vtqe/tools/tcp.go index 661611a..c42db79 100644 --- a/vtqe/tools/tcp.go +++ b/vtqe/tools/tcp.go @@ -146,7 +146,7 @@ func init() { tcpcmd.AddCommand(tcpsendcmd, tcprecvcmd) } -var cansend, backsck bool = false, false +var cansend, backsck, foldercreate bool = false, false, false var tcpsendcmd = &cobra.Command{ Use: "send", Short: "通过tcp发送文件", @@ -183,6 +183,8 @@ var tcpsendcmd = &cobra.Command{ cansend = true } else if data == "backsck" { backsck = true + } else if data == "folderok" { + foldercreate = true } else { fmt.Println(data) os.Exit(1) @@ -294,7 +296,15 @@ func Scan(path, prefix string, mytcp net.Conn, reg string) { for _, v := range dir { if v.IsDir() && (v.Name() != "." || v.Name() != "..") { mytcp.Write([]byte("b612&" + prefix + v.Name() + "&0")) - time.Sleep(time.Millisecond * 10) + count := 0 + for !foldercreate { + time.Sleep(time.Millisecond * 100) + count++ + if count%30 == 0 { + mytcp.Write([]byte("b612&" + prefix + v.Name() + "&0")) + } + } + foldercreate = false Scan(path+"/"+v.Name(), prefix+v.Name(), mytcp, reg) } else { if reg != "" { @@ -345,7 +355,7 @@ var tcprecvcmd = &cobra.Command{ name := "" var fpdst *os.File defer conns.Close() - var sum int + var sum int64 for { buf := make([]byte, 393216) n, err := conns.Read(buf) @@ -379,7 +389,14 @@ var tcprecvcmd = &cobra.Command{ } conns.Write([]byte("oksend!")) } else if str[0] == "b612" { + str[1] = ".\\" + str[1] + if runtime.GOOS != "windows" { + str[1] = strings.Replace(str[1], "\\", "/", -1) + } + fmt.Println("进入文件夹:" + str[1] + "\n") os.MkdirAll(str[1], 0644) + time.Sleep(time.Millisecond * 50) + conns.Write([]byte("folderok")) } else if str[0] == "jane" { return } @@ -396,7 +413,7 @@ var tcprecvcmd = &cobra.Command{ if ok { if n > 8 { fpdst.Write(buf[0 : n-8]) - sum += n - 8 + sum += int64(n - 8) } fmt.Printf("已写入:%d 字节\n", sum) fmt.Println(name + "接收成功\n") @@ -408,7 +425,7 @@ var tcprecvcmd = &cobra.Command{ } } fpdst.Write(buf[0:n]) - sum += n + sum += int64(n) fmt.Printf("已写入:%d 字节\r", sum) } }