-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathscp_test.go
53 lines (48 loc) · 1.05 KB
/
scp_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
package scp
import (
"net"
"os"
"testing"
"golang.org/x/crypto/ssh"
)
var RemoteADDR = os.Getenv("TEST_SSH_ADDR")
var Password = os.Getenv("TEST_SSH_PASSWORD")
var RemotePath = os.Getenv("TEST_SSH_PATH")
func TestSCP_Download(t *testing.T) {
scp, err := New(RemoteADDR, &ssh.ClientConfig{
User: "root",
Auth: []ssh.AuthMethod{ssh.Password(Password)},
HostKeyCallback: func(hostname string, remote net.Addr, key ssh.PublicKey) error {
return nil
},
}, WithSFTP(true))
if err != nil {
t.Error(err)
return
}
defer scp.Close()
err = scp.Download("/root/ep_package_daemon", "test")
if err != nil {
t.Error(err)
return
}
}
func TestSCP_Upload(t *testing.T) {
scp, err := New(RemoteADDR, &ssh.ClientConfig{
User: "root",
Auth: []ssh.AuthMethod{ssh.Password(Password)},
HostKeyCallback: func(hostname string, remote net.Addr, key ssh.PublicKey) error {
return nil
},
}, WithSFTP(true))
if err != nil {
t.Error(err)
return
}
defer scp.Close()
err = scp.Upload("test", RemotePath)
if err != nil {
t.Error(err)
return
}
}