gitee.com/h79/goutils@v1.22.10/common/ssh/scp_test.go (about)

     1  package ssh
     2  
     3  import (
     4  	"golang.org/x/crypto/ssh"
     5  	"net"
     6  	"testing"
     7  )
     8  
     9  func TestScp(t *testing.T) {
    10  
    11  	config, _ := WithPassword("root", "Hullo001@1010", func(hostname string, remote net.Addr, key ssh.PublicKey) error {
    12  		return nil
    13  	})
    14  	scp := NewScp(NewSession("8.129.77.207:22", &config))
    15  	res := scp.SendTo(0, &Option{Local: Path{Name: "./sftp.go"}, Remote: Path{Name: "/home/", IsDir: true, Mode: 0777}})
    16  
    17  	t.Log(res)
    18  
    19  	err := scp.ReceiveFrom(&Option{Local: Path{Name: "./sftpx", Mode: 0777}, Remote: Path{Name: "./home", IsDir: true}})
    20  
    21  	t.Log(err)
    22  }