Hi Brad:
Thanks so much for your suggestion. I run "ssh -v" and get useful
information as attachment.So,I modify the code,but occurred the different
problem as below.
ssh: handshake failed: ssh: unexpected message type 3 (expected one of [6])
// ftp
package main
import (
"fmt"
"github.com/pkg/sftp"
"golang.org/x/crypto/ssh"
)
func main() {
c := &ssh.ClientConfig{
User: "root",
Auth: []ssh.AuthMethod{
ssh.Password("12345678"),
},
}
connection, err := ssh.Dial("tcp", "192.168.44.129:22", c) // replace this
if err != nil {
fmt.Println(err)
return
}
server, err := sftp.NewClient(connection)
if err != nil {
fmt.Println(err)
return
}
dir, err := server.ReadDir(".")
if err != nil {
fmt.Println(err)
return
}
for _, fi := range dir {
fmt.Println(fi.Name())
}
}
2017-02-07 0:55 GMT+08:00 Brad Fitzpatrick <[email protected]>:
> From looking at:
>
> ssh: unable to authenticate, attempted methods [none], no supported
> methods remain
>
> It seems like your ssh server requires a different authentication mode and
> doesn't support KeyboardInteractive (a password).
>
> Does the standard ssh client work? What does "ssh -v" say?
>
>
> On Mon, Feb 6, 2017 at 1:25 AM, Robert Hsiung <[email protected]> wrote:
>
>> Dear all:
>> I tried to test sftp function with below coding,but occurred problem as
>> below. Please give me suggestions. Thanks so much.
>> ssh: handshake failed: ssh: unable to authenticate, attempted methods
>> [none], no supported methods remain
>>
>> >>>>
>> package main
>>
>> import (
>> "fmt"
>> "github.com/pkg/sftp"
>> "golang.org/x/crypto/ssh"
>> )
>>
>> func main() {
>>
>> c := &ssh.ClientConfig{
>> User: "root", // replace this
>> Auth: []ssh.AuthMethod{
>> ssh.KeyboardInteractive(func(user, instruction string, questions
>> []string, echos []bool) ([]string, error) {
>> // Just send the password back for all questions
>> answers := make([]string, len(questions))
>> for i, _ := range answers {
>> answers[i] = "12345678" // replace this
>> }
>>
>> return answers, nil
>> }),
>> },
>> }
>>
>> connection, err := ssh.Dial("tcp", "192.168.0.1:22", c) // replace this
>> if err != nil {
>> fmt.Println(err)
>> return
>> }
>>
>> server, err := sftp.NewClient(connection)
>> if err != nil {
>> fmt.Println(err)
>> return
>> }
>>
>> dir, err := server.ReadDir(".")
>> if err != nil {
>> fmt.Println(err)
>> return
>> }
>>
>> for _, fi := range dir {
>> fmt.Println(fi.Name())
>> }
>> }
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "golang-nuts" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to [email protected].
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
--
You received this message because you are subscribed to the Google Groups
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.