Skip to content

Instantly share code, notes, and snippets.

@dzlab
Created May 6, 2016 10:38
Show Gist options
  • 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)
}
@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