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))
|
"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) scp(user, localPath, remotePath string, recursive bool) (err error) {
|
||||||
func (q *System) CopyFile(user, localPath, remotePath string) (err error) {
|
|
||||||
addrPort := strings.Split(q.sshAddrPort, ":")
|
addrPort := strings.Split(q.sshAddrPort, ":")
|
||||||
addr := addrPort[0]
|
addr := addrPort[0]
|
||||||
port := addrPort[1]
|
port := addrPort[1]
|
||||||
|
|
||||||
cmd := exec.Command("scp", "-P", port,
|
args := []string{
|
||||||
|
"-P", port,
|
||||||
"-o", "StrictHostKeyChecking=no",
|
"-o", "StrictHostKeyChecking=no",
|
||||||
"-o", "LogLevel=error",
|
"-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()
|
output, err := cmd.CombinedOutput()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.New(string(output))
|
return errors.New(string(output))
|
||||||
@ -370,6 +379,16 @@ func (q *System) CopyFile(user, localPath, remotePath string) (err error) {
|
|||||||
return
|
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
|
// CopyAndInsmod copy kernel module to temporary file on qemu then insmod it
|
||||||
func (q *System) CopyAndInsmod(localKoPath string) (output string, err error) {
|
func (q *System) CopyAndInsmod(localKoPath string) (output string, err error) {
|
||||||
remoteKoPath := fmt.Sprintf("/tmp/module_%d.ko", rand.Int())
|
remoteKoPath := fmt.Sprintf("/tmp/module_%d.ko", rand.Int())
|
||||||
|
Loading…
Reference in New Issue
Block a user