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)