-
-
Save cygnetix/624a7c433858acbcd6bf to your computer and use it in GitHub Desktop.
Revisions
-
jedy revised this gist
Apr 10, 2015 . 1 changed file with 13 additions and 34 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -2,44 +2,19 @@ package main import ( "fmt" "golang.org/x/crypto/ssh" ) const privateKey = `content of id_rsa` func main() { signer, _ := ssh.ParsePrivateKey([]byte(privateKey)) clientConfig := &ssh.ClientConfig{ User: "jedy", Auth: []ssh.AuthMethod{ ssh.PublicKeys(signer), }, } client, err := ssh.Dial("tcp", "127.0.0.1:22", clientConfig) @@ -55,11 +30,15 @@ func main() { w, _ := session.StdinPipe() defer w.Close() content := "123456789\n" fmt.Fprintln(w, "D0755", 0, "testdir") // mkdir fmt.Fprintln(w, "C0644", len(content), "testfile1") fmt.Fprint(w, content) fmt.Fprint(w, "\x00") // transfer end with \x00 fmt.Fprintln(w, "C0644", len(content), "testfile2") fmt.Fprint(w, content) fmt.Fprint(w, "\x00") }() if err := session.Run("/usr/bin/scp -tr ./"); err != nil { panic("Failed to run: " + err.Error()) } } -
jedy revised this gist
Jul 25, 2013 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -21,7 +21,7 @@ func (k *keychain) Key(i int) (interface{}, error) { if i != 0 { return nil, nil } return &k.key.PublicKey, nil } func (k *keychain) Sign(i int, rand io.Reader, data []byte) (sig []byte, err error) { -
jedy revised this gist
Jul 23, 2013 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -11,7 +11,7 @@ import ( "io" ) const privateKey = `content of id_rsa` type keychain struct { key *rsa.PrivateKey -
jedy revised this gist
Aug 25, 2012 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -57,7 +57,7 @@ func main() { content := "123456789\n" fmt.Fprintln(w, "C0644", len(content), "testfile") fmt.Fprint(w, content) fmt.Fprint(w, "\x00") // 传输以\x00结束 }() if err := session.Run("/usr/bin/scp -qrt ./"); err != nil { panic("Failed to run: " + err.Error()) -
jedy revised this gist
Aug 25, 2012 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -21,7 +21,7 @@ func (k *keychain) Key(i int) (interface{}, error) { if i != 0 { return nil, nil } return k.key.PublicKey, nil } func (k *keychain) Sign(i int, rand io.Reader, data []byte) (sig []byte, err error) { -
jedy revised this gist
Aug 15, 2012 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -57,7 +57,7 @@ func main() { content := "123456789\n" fmt.Fprintln(w, "C0644", len(content), "testfile") fmt.Fprint(w, content) fmt.Fprint(w, "\x00") // 文件结束时加\0 }() if err := session.Run("/usr/bin/scp -qrt ./"); err != nil { panic("Failed to run: " + err.Error()) -
jedy created this gist
Aug 15, 2012 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,65 @@ // https://blogs.oracle.com/janp/entry/how_the_scp_protocol_works package main import ( "code.google.com/p/go.crypto/ssh" "crypto" "crypto/rsa" "crypto/x509" "encoding/pem" "fmt" "io" ) const privateKey = `` type keychain struct { key *rsa.PrivateKey } func (k *keychain) Key(i int) (interface{}, error) { if i != 0 { return nil, nil } return &k.key.PublicKey, nil } func (k *keychain) Sign(i int, rand io.Reader, data []byte) (sig []byte, err error) { hashFunc := crypto.SHA1 h := hashFunc.New() h.Write(data) digest := h.Sum(nil) return rsa.SignPKCS1v15(rand, k.key, hashFunc, digest) } func main() { block, _ := pem.Decode([]byte(privateKey)) rsakey, _ := x509.ParsePKCS1PrivateKey(block.Bytes) clientKey := &keychain{rsakey} clientConfig := &ssh.ClientConfig{ User: "wuhao", Auth: []ssh.ClientAuth{ ssh.ClientAuthKeyring(clientKey), }, } client, err := ssh.Dial("tcp", "127.0.0.1:22", clientConfig) 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()) } }