go - 我从客户端机器上使用 Go 运行 scp -i ssh "<filepath of remote linux machine> . ",但它返回 "no such file or directory"

标签 go scp

如何使用 Go 执行 scp -i ssh ". "?

我使用了以下代码片段。

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

最佳答案

我会做的。

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

关于go - 我从客户端机器上使用 Go 运行 scp -i ssh "<filepath of remote linux machine> . ",但它返回 "no such file or directory",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55034988/

相关文章:

csv - 将 csv.NewWriter() 传递给 Golang 中的另一个函数以异步写入文件

bash - 尝试使 rsync 命令更简单时出错

Go 解析模板 glob

bash - 登录远程 ssh 服务器时如何将文件复制到本地计算机

ssh - 脚本以SSH到计算机并执行SCP

ios - 当提示输入远程主机的 SCP 密码时,如何将回车添加到 bash?

ssh - 如何通过scp命令通过跳机将文件复制到远程计算机

go - Go语言内置的http服务器是生产服务器吗?

oop - 确保嵌入式结构实现接口(interface)而不引入歧义

go - 结构图和 "assignment to entry in nil map"的图