修复windows向Linux传输发生文件夹错误

master
兔子 5 years ago
parent 196a469c34
commit eec673f640

@ -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)
}
}

Loading…
Cancel
Save