我从客户端计算机使用Go运行了scp -i ssh“ <filepath of =”“ remote =”“ linux =”“ machine =”“>。”,但是它返回“没有这样的文件或目录”

时间:2019-03-07 02:11:23

标签: go scp

如何使用Go执行scp -i ssh“。”?

我使用了以下代码段。

cmd := exec.Command("scp -i dragonstone.pem <user>@ubuntu:<file location> .")
err = cmd.Run()

1 个答案:

答案 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.")
}