Our Products:   CompleteFTP  edtFTPnet/Free  edtFTPnet/PRO  edtFTPj/Free  edtFTPj/PRO
0 votes
1.3k views
in .NET FTP by (51.1k points)
A user asked us how to use edtFTPnet/PRO to fetch the public key from a server.

Here's a method that does this:
using EnterpriseDT.Util.Debug;
using EnterpriseDT.Net.Ftp;
using EnterpriseDT.Net.Ssh;
...
private static void PrintPublicKey(string serverAddress, SSHPublicKeyAlgorithm algorithm)
{
    try
    {
        Logger.CurrentLevel = Level.OFF;
        SecureFTPConnection secureFTPConnection = new SecureFTPConnection();
        secureFTPConnection.ServerAddress = serverAddress;
        secureFTPConnection.Protocol = FileTransferProtocol.SFTP;
        secureFTPConnection.UserName = secureFTPConnection.Password = "doesnt_matter";
        secureFTPConnection.PreferredHostKeyAlgorithms = algorithm;
        secureFTPConnection.ServerValidation = SecureFTPServerValidationType.Callback;
        secureFTPConnection.ValidatingServer += delegate(object sender, ServerValidationEventArgs e)
        {
            Console.Out.WriteLine(serverAddress + " " + e.SSHPublicKey.ToStringOpenSSH(""));
        };
        secureFTPConnection.Connect();
        secureFTPConnection.Close();
    }
    catch (Exception)
    {
    }
}


- Hans (EnterpriseDT)

Please log in or register to answer this question.

Categories

...