I am trying to connect to sftp via Rebex with Private Key Authentication. But I am getting below exception "The connection was closed by the server. Make sure you are connecting to an SSH or SFTP server"
My code is as below:
IsActive = client.GetConnectionState();
txtConnectivityStatus.Text += "SFTP Connection State:" + IsActive.Connected + Environment.NewLine;
if (IsActive.Connected == false)
{
try
{
client.Connect(txtHost.Text, Convert.ToInt32(txtPort.Text));
SshPrivateKey privateKey = new SshPrivateKey(txtPvtKeyPath.Text, txtPvtKeyPwd.Text);
client.Login(txtUserName.Text, txtPassword.Text, privateKey);
}
catch (Exception ex)
{
txtConnectivityStatus.Text += "Error in SFTP Private Key Authentication-Exception:" + ex.Message + Environment.NewLine + "Inner Exception:" + ex.InnerException + Environment.NewLine + "Stack Trace" + ex.StackTrace + Environment.NewLine;
}
}