ssh tunnel forwardedport를 통해 원격 MySql 연결을 만들려고했습니다. sshClient 연결이 정상입니다. 전달 된 포트가 정상적으로 시작됩니다. MysqlConnection에 연결하려고하면 "예기치 않은 패킷 형식으로 인해 핸드 셰이크가 실패했습니다"라는 메시지와 함께 System.Net.IO.IOException이 발생합니다.C# ssh.net 터널 mysql 클라이언트 ioexception
포트는 100 % 확실합니다. 다른 기본 응용 프로그램 (예 : HeidiSQL) 내 애플 리케이션이 포트를 만들면 연결할 수 있습니다.
PrivateKeyFile file = new PrivateKeyFile(rsaFile);
client = new SshClient(host, port, username, file);
forwardBoundHost = "127.0.0.1";
forwardBoundPort = 33306;
forwardHost = "127.0.0.1";
forwardPort = 3306;
port = new ForwardedPortLocal(forwardBoundHost, forwardBoundPort, forwardHost, forwardPort);
if(this.response != null){
port.RequestReceived += response;
}
client.Connect();
client.AddForwardedPort(port);
port.Exception += port_Exception;
port.Start();
if (port.IsStarted)
{
cb = new MySqlConnectionStringBuilder()
{
AllowBatch = true,
Server = this.host,
Port = this.port,
UserID = this.dbuser,
Password = this.dbpassword,
Database = this.database,
SslMode = MySqlSslMode.Required,
Keepalive = 60,
ConnectionProtocol = MySqlConnectionProtocol.Tcp,
CharacterSet = "utf8"
};
cb.ConnectionProtocol = MySqlConnectionProtocol.Tcp;
MySqlConnection connection = new MySqlConnection(cb.GetConnectionString(true));
MySqlCommand cmd;
MySqlDataReader reader;
try
{
Console.WriteLine("Mysql client conn");
connection.Open();
}
cmd = connection.CreateCommand();
cmd.CommandText = queryString;
cmd.Prepare();
Array myp = new Array[param.Length];
int i = 0;
foreach (String oneParam in param)
{
myp.SetValue(new MySqlParameter(oneParam, MySqlDbType.String), i);
i++;
}
cmd.Parameters.AddRange(myp);
reader = cmd.ExecuteReader();
}
catch (Exception e)
{
//Logger(e.ToString());
throw (e);
}
finally
{
if (connection.State == System.Data.ConnectionState.Open)
connection.Close();
}
return reader;