-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathftp-operation.go
60 lines (52 loc) · 1.57 KB
/
ftp-operation.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package main
import (
"bufio"
"context"
"github.com/dutchcoders/goftp"
"io"
"k8s.io/client-go/rest"
"strconv"
)
//func ftpUploader(c *Client, r io.Reader) {
func ftpUploader(c *Client, result2 *rest.Request) {
dirPath := "user/" + strconv.Itoa(c.userIds.Uid) + "/" + strconv.Itoa(c.userIds.Tid) + "/log/"
var err error
var ftp *goftp.FTP
AGAIN:
podLogs2, err := result2.Stream(context.TODO())
if err != nil {
Error.Printf("[%d, %d]: podLogs2 err: %s\n", c.userIds.Uid, c.userIds.Tid, err)
return
}
defer podLogs2.Close()
/*rr := bufio.NewReader(podLogs2)
_, err = rr.ReadBytes('\n')
if err == io.EOF {
Trace.Println("FTP stream EOF get")
goto AGAIN
}*/
if ftp, err = goftp.Connect(FTPSERVER); err != nil {
Error.Printf("[%d, %d]: goftp connect err:%s\n", c.userIds.Uid, c.userIds.Tid, err)
}
defer ftp.Close()
Trace.Printf("[%d, %d]: goftp connect successfully\n", c.userIds.Uid, c.userIds.Tid)
// Username / password authentication
if err = ftp.Login("ftper", "admin"); err != nil {
Error.Printf("[%d, %d]: goftp login err:%s\n", c.userIds.Uid, c.userIds.Tid, err)
}
if err := ftp.Stor(dirPath+c.hub.clients[*c.userIds].Head.rm.FtpFileName, podLogs2); err != nil {
Error.Printf("[%d, %d]: goftp stor err:%s, activate again\n", c.userIds.Uid, c.userIds.Tid, err)
podLogs2.Close()
ftp.Close()
goto AGAIN
} else {
rr := bufio.NewReader(podLogs2)
_, err = rr.ReadBytes('\n')
if err == io.EOF {
Trace.Printf("[%d, %d]: FTP stream EOF get, activate again...\n", c.userIds.Uid, c.userIds.Tid)
podLogs2.Close()
ftp.Close()
goto AGAIN
}
}
}