20

This is my code using SSH.NET

using (var sftp = new SftpClient(host, username, password))
{                
    sftp.Connect();  
}

It works on a SFTP I installed on my local computer but when I point it at a real SFTP server from a client I get a Renci.SshNet.Common.SshAuthenticationException: No suitable authentication method found to complete authentication.

I cannot find any documentation on what authentication methods I should be using and on File Zilla a simple user name and password is doing the trick.

Can anyone please advise?

0

2 Answers 2

44

I found the answer (at least for my problem, which seems to be the same as the op requested):

I had to change the Authentication to KeyboardInteractiveAuthenticationMethod

So this works now:

KeyboardInteractiveAuthenticationMethod keybAuth = new KeyboardInteractiveAuthenticationMethod(SFTP_USR);
keybAuth.AuthenticationPrompt += new EventHandler<AuthenticationPromptEventArgs>(HandleKeyEvent);

ConnectionInfo conInfo = new ConnectionInfo(SFTP_HST, SFTP_PRT, SFTP_USR, keybAuth);

using (SftpClient sftp = new SftpClient(conInfo))
{
    sftp.Connect();

    // Do SFTP Stuff, Upload, Download,...

    sftp.Disconnect();
}

HandleKeyEvent then passes the Password:

private void HandleKeyEvent(object sender, AuthenticationPromptEventArgs e)
{ 
    foreach (AuthenticationPrompt prompt in e.Prompts)
    {
        if (prompt.Request.IndexOf("Password:", StringComparison.InvariantCultureIgnoreCase) != -1)
        {
            prompt.Response = SFTP_PWD;
        }
    }
}
Sign up to request clarification or add additional context in comments.

1 Comment

Explanation here: "This one was doing my head in. It turned out some servers do not support PasswordAuthenticationMethod, so you'll have to use keyboardInteractiveAuthenticationMethod, and then handle the AuthenticationPrompt event to provide the password:"
1

Ok so the answer to my problem is that it wasn't an sftp server. It was a simple ftp server so i just used a webrequest.

Check the server is actually an sftp server first.

1 Comment

That's exactly what I expected and what we could have easily determined from the FileZilla log.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.