Skip to content

eleztian/go-scp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

go-scp

go-scp makes it easy to copy files/folders between two hosts over SSH. It uses the golang.org/x/crypto/ssh package to establish a secure connection with the remote host and transfers files via the SCP protocol.

Example

package main

import (
	"golang.org/x/crypto/ssh"
	"net"
)

var (
	addr     = "192.168.0.102:22"
	user     = "root"
	password = "password"
)

func main() {

	cfg := &ssh.ClientConfig{
		Config: ssh.Config{},
		User:   user,
		Auth: []ssh.AuthMethod{
			ssh.Password(password),
		},
		HostKeyCallback: func(hostname string, remote net.Addr, key ssh.PublicKey) error {
			return nil
		},
	}

	scp, err := New(addr, cfg)
	checkErr(err)
	defer scp.Close()

	err = scp.Upload("testdata", "/root/scp")
	checkErr(err)
	err = scp.Download("/root/scp", "testdata")
	checkErr(err)
}

func checkErr(err error) {
	if err != nil {
		panic(err)
	}
}

About

SCP SSH

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages