qemu: add CopyDirectory (via scp)
This commit is contained in:
parent
668bc1e391
commit
d59049e531
@ -352,16 +352,25 @@ func (q System) AsyncCommand(user, cmd string) (err error) {
|
||||
"nohup sh -c '%s' > /dev/null 2> /dev/null < /dev/null &", cmd))
|
||||
}
|
||||
|
||||
// CopyFile is copy file from local machine to remote through ssh/scp
|
||||
func (q *System) CopyFile(user, localPath, remotePath string) (err error) {
|
||||
func (q System) scp(user, localPath, remotePath string, recursive bool) (err error) {
|
||||
addrPort := strings.Split(q.sshAddrPort, ":")
|
||||
addr := addrPort[0]
|
||||
port := addrPort[1]
|
||||
|
||||
cmd := exec.Command("scp", "-P", port,
|
||||
args := []string{
|
||||
"-P", port,
|
||||
"-o", "StrictHostKeyChecking=no",
|
||||
"-o", "LogLevel=error",
|
||||
localPath, user+"@"+addr+":"+remotePath)
|
||||
}
|
||||
|
||||
if recursive {
|
||||
args = append(args, "-r")
|
||||
}
|
||||
|
||||
args = append(args, localPath, user+"@"+addr+":"+remotePath)
|
||||
|
||||
cmd := exec.Command("scp", args...)
|
||||
|
||||
output, err := cmd.CombinedOutput()
|
||||
if err != nil {
|
||||
return errors.New(string(output))
|
||||
@ -370,6 +379,16 @@ func (q *System) CopyFile(user, localPath, remotePath string) (err error) {
|
||||
return
|
||||
}
|
||||
|
||||
// CopyFile from local machine to remote via scp
|
||||
func (q System) CopyFile(user, localPath, remotePath string) (err error) {
|
||||
return q.scp(user, localPath, remotePath, false)
|
||||
}
|
||||
|
||||
// CopyDirectory from local machine to remote via scp
|
||||
func (q System) CopyDirectory(user, localPath, remotePath string) (err error) {
|
||||
return q.scp(user, localPath, remotePath, true)
|
||||
}
|
||||
|
||||
// CopyAndInsmod copy kernel module to temporary file on qemu then insmod it
|
||||
func (q *System) CopyAndInsmod(localKoPath string) (output string, err error) {
|
||||
remoteKoPath := fmt.Sprintf("/tmp/module_%d.ko", rand.Int())
|
||||
|
Loading…
Reference in New Issue
Block a user