SCP中的SCP客户端 [英] SCP Client in Go

查看:270
本文介绍了SCP中的SCP客户端的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在努力和 golang的ssh客户端,但被告知密码因为freesshd服务器与Go的ssh客户端不兼容,所以我只安装了另一个(PowerShell Server),并且我可以成功连接到服务器。



我的问题是没有结束,因为我现在需要将文件从本地传输到远程,并且这只能通过scp完成。我被定向到 scp客户端,并有两个问题。


  1. 我运行它并得到这个:

  2. 我刚进入我的.ssh文件夹,看到一个github_rsa并使用该私钥,我确信这不是正确的使用方法,但不会看到某种错误或无效私钥,而不是上面的结果? 你被导向的代码被破坏了。该示例还使用公钥认证,这不一定是您唯一的选择。如果您可以允许使用密码验证,您可以让自己更轻松一点。



    我只是通过修改您使用的示例自行上传:

     包主

    导入(
    code.google.com/p/go.crypto/ssh
    fmt


    类型密码字符串

    func(p密码)密码(_字符串)(字符串,错误){
    返回字符串(p),nil
    }

    func main(){

    //拨号代码取自ssh包示例
    config:=& ssh.ClientConfig {
    User:username,
    Auth:[] ssh.ClientAuth {
    ssh.ClientAuthPassword(password(password)),
    },
    }
    client,err:= ssh.Dial(tcp,127.0.0.1:22,config)
    if err!= nil {
    panic (无法拨号:+ err.Error())
    }

    session,err:= client.NewSession()
    if err!= nil {
    恐慌(无法创建会话:+ err.Error())
    }
    推迟session.Close()


    去func(){
    w,_:= session .StdinPipe()
    推迟w.Close()
    内容:=123456789\\\

    fmt.Fprintln(w,C0644,len(content),testfile)
    fmt.Fprint(w,content)
    fmt.Fprint(w,\x00)
    }()
    if err:= session.Run(/ usr / bin / scp -qrt ./); err!= nil {
    panic(Failed to run:+ err.Error())
    }

    }


    I was struggling with and ssh client for golang but was told that the ciphers for the freesshd server was incompatible with the ssh client for Go, so I just installed another one (PowerShell Server) and I can successfully connect to the server.

    My problem is not over because I now need to transfer files from local to remote, and this can only be done through scp. I was directed to this scp client for go and have two issues.

    1. I run it and get this:

    2. Where or how can I access the contents of id_rsa needed for privateKey? I just went in my .ssh folder and saw a github_rsa and used that private key, I'm sure that this is not the correct one to use but wouldn't I see some kind of error or invalid private key and not the result above?

    解决方案

    The code you were directed to is broken. The example also uses the public key authentication, which is not necessarily your only option. If you can allow password authentication instead, you can make it a bit easier for yourself.

    I just made an upload myself by modifying the example you used:

    package main
    
    import (
        "code.google.com/p/go.crypto/ssh"
        "fmt"
    )
    
    type password string
    
    func (p password) Password(_ string) (string, error) {
        return string(p), nil
    }
    
    func main() {
    
        // Dial code is taken from the ssh package example
        config := &ssh.ClientConfig{
            User: "username",
            Auth: []ssh.ClientAuth{
                ssh.ClientAuthPassword(password("password")),
            },
        }
        client, err := ssh.Dial("tcp", "127.0.0.1:22", config)
        if err != nil {
            panic("Failed to dial: " + err.Error())
        }
    
        session, err := client.NewSession()
        if err != nil {
            panic("Failed to create session: " + err.Error())
        }
        defer session.Close()
    
    
        go func() {
            w, _ := session.StdinPipe()
            defer w.Close()
            content := "123456789\n"
            fmt.Fprintln(w, "C0644", len(content), "testfile")
            fmt.Fprint(w, content)
            fmt.Fprint(w, "\x00")
        }()
        if err := session.Run("/usr/bin/scp -qrt ./"); err != nil {
            panic("Failed to run: " + err.Error())
        }
    
    }
    

    这篇关于SCP中的SCP客户端的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆