一、客户端实现方案:
func sendFile(filePath string, conn net.Conn) {
fileInfo, err := os.Stat(filePath)
fmt.Println("Error getting file info:", err)
fileName := fileInfo.Name()
conn.Write([]byte(fileName))
file, err := os.Open(filePath)
fmt.Println("Error opening file:", err)
_, err = io.Copy(conn, file)
fmt.Println("Error copying file content:", err)
fmt.Printf("File %s sent.\n", fileName)
conn, err := net.Dial("tcp", "localhost:8080")
fmt.Println("Error connecting to server:", err)
filePath := "C:\\zhangsan.txt" // 替换为实际文件