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) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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"},
}
},