Subject: How to Use Public Key Authentication with SFTP Server
Date: 2019-12-17 20:22:59
From: Lee
Source: use-public-key-authentication-sftp-server
----------------------------------------------------------------------

Can you please provide an example of how public key authentication works with sftp server?  I'm guessing something like:

```
server.PreAuthentication = ServerOnPreAuthentication;

private static void ServerOnPreAuthentication(object sender, PreAuthenticationEventArgs e)
{
    e.Accept(AuthenticationMethods.PublicKey);
}
```

And then maybe something like this:

```
server.Authentication  = ServerOnAuthentication;

private static void ServerOnAuthentication(object sender, AuthenticationEventArgs e)
{
    if (e.Key.???)
    {
        var user = AddUser((SftpSshServer)sender, e.UserName, e.Password, userPath);
        e.Accept(user);
    }
    else
    {
        e.Reject();
    }
}

```

The problem is e.Key is always null for me, no matter what I do.  I am testing this with FileZilla and a Logon Type of Key file where I specify a ppk file.

----------------------------------------------------------------------

Note: This question has been asked on the Q&A forum of Thang Dang's fraudulent ComponentPro brand
If you purchased anything from ComponentPro, you have been scammed. Contact the payment processor
who sold you the license and ask for your money back.

Back to ComponentPro Q&A Forum Index