Skip to content

Instantly share code, notes, and snippets.

@dzlab
Created May 6, 2016 10:38
Show Gist options
  • Star 9 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save dzlab/939e4d1ef143f5683a2a62a203362ad8 to your computer and use it in GitHub Desktop.
Save dzlab/939e4d1ef143f5683a2a62a203362ad8 to your computer and use it in GitHub Desktop.
an example of sftp in golang
package main
import (
"github.com/pkg/sftp"
"golang.org/x/crypto/ssh"
)
func main() {
addr := “my_ftp_server:22"
config := &ssh.ClientConfig{
User: “my_user",
Auth: []ssh.AuthMethod{
ssh.Password(“my_password"),
},
//Ciphers: []string{"3des-cbc", "aes256-cbc", "aes192-cbc", "aes128-cbc"},
}
conn, err := ssh.Dial("tcp", addr, config)
if err != nil {
panic("Failed to dial: " + err.Error())
}
client, err := sftp.NewClient(conn)
if err != nil {
panic("Failed to create client: " + err.Error())
}
// Close connection
defer client.Close()
cwd, err := client.Getwd()
println("Current working directory:", cwd)
}
@dzlab
Copy link
Author

dzlab commented May 6, 2016

If you get this error message panic: ssh: handshake failed: ssh: no common algorithm for client to server cipher;, then add for instance "aes128-cbc" to supportedCiphers in $GOPATH/src/golang.org/x/crypto/ssh/common.go. More details in this issue.

@DaveJKing
Copy link

No need to edit the package :-)

config := &ssh.ClientConfig{
User: “my_user",
Auth: []ssh.AuthMethod{
ssh.Password(“my_password"),
},
Config: ssh.Config{
Ciphers: []string{"aes128-cbc"},
}
},

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment