Created
May 6, 2016 10:38
-
-
Save dzlab/939e4d1ef143f5683a2a62a203362ad8 to your computer and use it in GitHub Desktop.
an example of sftp in golang
This file contains 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 characters
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) | |
} |
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
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"
tosupportedCiphers
in$GOPATH/src/golang.org/x/crypto/ssh/common.go
. More details in this issue.