|
|
@ -146,7 +146,7 @@ func init() {
|
|
|
|
tcpcmd.AddCommand(tcpsendcmd, tcprecvcmd)
|
|
|
|
tcpcmd.AddCommand(tcpsendcmd, tcprecvcmd)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var cansend bool = false
|
|
|
|
var cansend, backsck bool = false, false
|
|
|
|
var tcpsendcmd = &cobra.Command{
|
|
|
|
var tcpsendcmd = &cobra.Command{
|
|
|
|
Use: "send",
|
|
|
|
Use: "send",
|
|
|
|
Short: "通过tcp发送文件",
|
|
|
|
Short: "通过tcp发送文件",
|
|
|
@ -181,6 +181,8 @@ var tcpsendcmd = &cobra.Command{
|
|
|
|
data := string(buf[0:n])
|
|
|
|
data := string(buf[0:n])
|
|
|
|
if data == "oksend!" {
|
|
|
|
if data == "oksend!" {
|
|
|
|
cansend = true
|
|
|
|
cansend = true
|
|
|
|
|
|
|
|
} else if data == "backsck" {
|
|
|
|
|
|
|
|
backsck = true
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
fmt.Println(data)
|
|
|
|
fmt.Println(data)
|
|
|
|
os.Exit(1)
|
|
|
|
os.Exit(1)
|
|
|
@ -230,13 +232,16 @@ func tcpupload(file, prefix string, mytcp net.Conn) error {
|
|
|
|
cansend = false
|
|
|
|
cansend = false
|
|
|
|
sum := 0
|
|
|
|
sum := 0
|
|
|
|
for {
|
|
|
|
for {
|
|
|
|
buf := make([]byte, 1048576)
|
|
|
|
buf := make([]byte, 524288)
|
|
|
|
n, err := fpsrc.Read(buf)
|
|
|
|
n, err := fpsrc.Read(buf)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
if err == io.EOF {
|
|
|
|
if err == io.EOF {
|
|
|
|
time.Sleep(time.Millisecond * 8)
|
|
|
|
|
|
|
|
err = nil
|
|
|
|
err = nil
|
|
|
|
|
|
|
|
for !backsck {
|
|
|
|
|
|
|
|
time.Sleep(time.Millisecond * 150)
|
|
|
|
mytcp.Write([]byte{1, 9, 9, 6, 1, 1, 2, 7, 6, 6, 6, 1, 1, 2, 7})
|
|
|
|
mytcp.Write([]byte{1, 9, 9, 6, 1, 1, 2, 7, 6, 6, 6, 1, 1, 2, 7})
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
backsck = false
|
|
|
|
break
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fmt.Println(err)
|
|
|
|
fmt.Println(err)
|
|
|
@ -252,7 +257,6 @@ func tcpupload(file, prefix string, mytcp net.Conn) error {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fmt.Printf("当前已传输:%f\n\n", 100.000000)
|
|
|
|
fmt.Printf("当前已传输:%f\n\n", 100.000000)
|
|
|
|
fpsrc.Close()
|
|
|
|
fpsrc.Close()
|
|
|
|
time.Sleep(time.Millisecond * 8)
|
|
|
|
|
|
|
|
return nil
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -343,7 +347,7 @@ var tcprecvcmd = &cobra.Command{
|
|
|
|
defer conns.Close()
|
|
|
|
defer conns.Close()
|
|
|
|
var sum int
|
|
|
|
var sum int
|
|
|
|
for {
|
|
|
|
for {
|
|
|
|
buf := make([]byte, 1048576)
|
|
|
|
buf := make([]byte, 524288)
|
|
|
|
n, err := conns.Read(buf)
|
|
|
|
n, err := conns.Read(buf)
|
|
|
|
|
|
|
|
|
|
|
|
if !canrecv {
|
|
|
|
if !canrecv {
|
|
|
@ -377,20 +381,25 @@ var tcprecvcmd = &cobra.Command{
|
|
|
|
return
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
if n == 15 {
|
|
|
|
if n < 524288 && buf[n-1] == byte(7) {
|
|
|
|
ok := func() bool {
|
|
|
|
ok := func() bool {
|
|
|
|
for k, v := range []byte{1, 9, 9, 6, 1, 1, 2, 7, 6, 6, 6, 1, 1, 2, 7} {
|
|
|
|
for k, v := range []byte{1, 9, 9, 6, 1, 1, 2, 7, 6, 6, 6, 1, 1, 2, 7} {
|
|
|
|
if buf[k] != v {
|
|
|
|
if buf[n-15+k] != v {
|
|
|
|
return false
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
return true
|
|
|
|
}()
|
|
|
|
}()
|
|
|
|
if ok {
|
|
|
|
if ok {
|
|
|
|
|
|
|
|
if n > 15 {
|
|
|
|
|
|
|
|
fpdst.Write(buf[0 : n-15])
|
|
|
|
|
|
|
|
}
|
|
|
|
fmt.Printf("已写入:%d 字节\n", sum)
|
|
|
|
fmt.Printf("已写入:%d 字节\n", sum)
|
|
|
|
fmt.Println(name + "接收成功\n")
|
|
|
|
fmt.Println(name + "接收成功\n")
|
|
|
|
fpdst.Close()
|
|
|
|
fpdst.Close()
|
|
|
|
canrecv = false
|
|
|
|
canrecv = false
|
|
|
|
|
|
|
|
sum = 0
|
|
|
|
|
|
|
|
conns.Write([]byte("backsck"))
|
|
|
|
continue
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|