0 votes
by (180 points)

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;
                    }


            }
Applies to: Rebex SFTP

1 Answer

0 votes
by (73.5k points)

It seems that you are not connecting to an SFTP server.

Please make sure your server is configured to use SFTP protocol. The common mistake is that the server is configured to use FTP or FTP/SSL protocols.

More about differences between FTP and SFTP is discussed at https://www.rebex.net/kb/secure-ftp/

If your server is using FTP, please use Rebex FTP library.

...