-
Notifications
You must be signed in to change notification settings - Fork 97
/
example_test.go
64 lines (52 loc) · 892 Bytes
/
example_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
package smb2_test
import (
"fmt"
"io"
"io/ioutil"
"net"
"github.com/hirochachacha/go-smb2"
)
func Example() {
conn, err := net.Dial("tcp", "localhost:445")
if err != nil {
panic(err)
}
defer conn.Close()
d := &smb2.Dialer{
Initiator: &smb2.NTLMInitiator{
User: "Guest",
Password: "",
Domain: "MicrosoftAccount",
},
}
c, err := d.Dial(conn)
if err != nil {
panic(err)
}
defer c.Logoff()
fs, err := c.Mount(`\\localhost\share`)
if err != nil {
panic(err)
}
defer fs.Umount()
f, err := fs.Create("hello.txt")
if err != nil {
panic(err)
}
defer fs.Remove("hello.txt")
defer f.Close()
_, err = f.Write([]byte("Hello world!"))
if err != nil {
panic(err)
}
_, err = f.Seek(0, io.SeekStart)
if err != nil {
panic(err)
}
bs, err := ioutil.ReadAll(f)
if err != nil {
panic(err)
}
fmt.Println(string(bs))
// Hello world!
}