From 3ecfc81c1b62477c91d2cc9fec1cb288f01dea68 Mon Sep 17 00:00:00 2001 From: Smart-SangGe <2251250136@qq.com> Date: Fri, 22 Jul 2022 23:55:33 +0800 Subject: [PATCH] finish upload function --- 123 | 1 - console.go | 30 ++++++++++-------------------- 2 files changed, 10 insertions(+), 21 deletions(-) delete mode 100644 123 diff --git a/123 b/123 deleted file mode 100644 index 9224ccc..0000000 --- a/123 +++ /dev/null @@ -1 +0,0 @@ -2adjfhasjdfjadhkfahsdk diff --git a/console.go b/console.go index 868f349..598886d 100644 --- a/console.go +++ b/console.go @@ -292,29 +292,19 @@ func sender(conn *net.TCPConn, exit chan string, receive chan int) { log.Fatal(err) } - conn.Write([]byte("dd of=" + args[2] + " status=none" + "\n")) uploadbuf, _ := os.ReadFile(args[1]) - // cmd := append([]byte("dd if="), uploadbuf...) - // cmd1 := append(cmd, []byte("|dd of="+args[2]+" status=none\n")...) - //conn.Write([]byte("")) - // conn.Write([]byte("echo ")) + file, _ := os.Stat(args[1]) + size := file.Size() + count := size / 1024 + morecount := size % 1024 + if morecount != 0 { + count++ + } + strcount := strconv.Itoa(int(count)) + conn.Write([]byte("dd of=" + args[2] + " status=none bs=1024 count=" + strcount + "\n")) conn.Write(uploadbuf) - conn.CloseWrite() - //conn.Write([]byte("|dd of=" + args[2])) - //conn.Write([]byte(">" + args[2])) - //n, _ := conn.Write(uploadbuf) - // fmt.Print(n) - // fmt.Print(len(uploadbuf)) - // if n == len(uploadbuf) { - // // fmt.Println("failed to upload") - // // fmt.Print(env1.username + " > ") - // fmt.Print(env1.username + " > ") - // return - // } + fmt.Print("Upload success") fmt.Print(env1.username + " > ") - receive <- 1 - // fmt.Println("failed to upload") - // fmt.Print(env1.username + " > ") return }