forked from secsy/goftp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
raw_conn_test.go
77 lines (61 loc) · 1.22 KB
/
raw_conn_test.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
// Copyright 2015 Muir Manders. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
package goftp
import (
"io/ioutil"
"strings"
"testing"
)
func TestRawConn(t *testing.T) {
for _, addr := range ftpdAddrs {
c, err := DialConfig(goftpConfig, addr)
if err != nil {
t.Fatal(err)
}
rawConn, err := c.OpenRawConn()
if err != nil {
t.Fatal(err)
}
code, msg, err := rawConn.SendCommand("FEAT")
if err != nil {
t.Fatal(err)
}
if code != 211 {
t.Errorf("got %d", code)
}
if !strings.Contains(msg, "REST") {
t.Errorf("got %s", msg)
}
dcGetter, err := rawConn.PrepareDataConn()
if err != nil {
t.Fatal(err)
}
_, _, err = rawConn.SendCommand("LIST")
if err != nil {
t.Fatal(err)
}
dc, err := dcGetter()
if err != nil {
t.Fatal(err)
}
got, err := ioutil.ReadAll(dc)
if err != nil {
t.Fatal(err)
}
if !strings.Contains(string(got), "lorem.txt") {
t.Errorf("got %s", got)
}
dc.Close()
code, _, err = rawConn.ReadResponse()
if err != nil {
t.Fatal(err)
}
if code != 226 {
t.Errorf("got: %d", code)
}
if err := rawConn.Close(); err != nil {
t.Error(err)
}
}
}