-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.go
42 lines (40 loc) · 854 Bytes
/
client.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package main
import (
"crypto/tls"
"errors"
"log"
)
func connectAndSendFilesToServer(serverAddr string, pass string, files []string) error {
conn, err := tls.Dial("tcp", serverAddr, &tls.Config{InsecureSkipVerify: true})
if err != nil {
return err
}
defer conn.Close()
err = writePass(conn, pass)
if err != nil {
return err
}
for _, file := range files {
res, err := fileIsReadable(file)
if err != nil {
_, _ = conn.Write([]byte("e"))
return err
}
if !res {
_, _ = conn.Write([]byte("e"))
return errors.New("file " + file + " is not readable")
}
_, err = conn.Write([]byte("f"))
if err != nil {
return err
}
err = writeFile(conn, file)
if err != nil {
_, _ = conn.Write([]byte("e"))
return err
}
log.Println("File successfully sent:", file)
}
_, err = conn.Write([]byte("e"))
return err
}