如何使用Go执行scp -i ssh“。”?
我使用了以下代码段。
cmd := exec.Command("scp -i dragonstone.pem <user>@ubuntu:<file location> .")
err = cmd.Run()
答案 0 :(得分:0)
我会做的。
package main
import (
"fmt"
"os"
"os/exec"
)
func main() {
cmd := "scp"
args := []string{"-i", "dragonstone.pem", "<user>@ubuntu:<file location>", "."}
if err := exec.Command(cmd, args...).Run(); err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
fmt.Println("Successfully.")
}