Settings settings; const Settings::SSH &ssh{settings.loadSSH()}; ssh_key key;
int code = ssh_pki_import_privkey_file("key.ossh", ssh.password.toStdString().c_str(), NULL, NULL, &key);
if(code != SSH_OK)
{
_logger->logOnce("Bad private key!");
return false;
}
ssh_options_set(_ssh, SSH_OPTIONS_HOST, ssh.host.toStdString().c_str());
code = ssh_connect(_ssh);
if(code != SSH_OK)
{
_logger->logSshErrorOnce("Unable to connect to host!", _ssh);
return false;
}
code = ssh_userauth_publickey(_ssh, ssh.login.toStdString().c_str(), key);
if(code != SSH_AUTH_SUCCESS)
{
_logger->logSshErrorOnce("Unable to authorize!", _ssh);
return false;
}
code = ssh_channel_open_forward(_channel, ssh.host.toStdString().c_str(), 22, "localhost", 3307);
if(code != SSH_OK)
{
_logger->logSshErrorOnce("Unable to create ssh-channel!", _ssh);
return false;
}
Settings settings; const Settings::SSH &ssh{settings.loadSSH()}; ssh_key key;
int code = ssh_pki_import_privkey_file("key.ossh", ssh.password.toStdString().c_str(), NULL, NULL, &key);
if(code != SSH_OK)
{
_logger->logOnce("Bad private key!");
return false;
}
ssh_options_set(_ssh, SSH_OPTIONS_HOST, ssh.host.toStdString().c_str());
code = ssh_connect(_ssh);
if(code != SSH_OK)
{
_logger->logSshErrorOnce("Unable to connect to host!", _ssh);
return false;
}
code = ssh_userauth_publickey(_ssh, ssh.login.toStdString().c_str(), key);
if(code != SSH_AUTH_SUCCESS)
{
_logger->logSshErrorOnce("Unable to authorize!", _ssh);
return false;
}
code = ssh_channel_open_forward(_channel, ssh.host.toStdString().c_str(), 22, "localhost", 3307);
if(code != SSH_OK)
{
_logger->logSshErrorOnce("Unable to create ssh-channel!", _ssh);
return false;
}
To copy to clipboard, switch view to plain text mode
It works and there are no errors. BUT, what I should do next to transfer data from my Qt database to ssh tunnel? May be I need to use something in addition (classes, libs...)?
const Settings::Database &db{settings.loadDatabase()};
_db.setPort(3307);
_db.setHostName("localhost");
_db.setDatabaseName("test_db");
_db.setUserName(db.login);
_db.setPassword(db.password);
_db.open();
const Settings::Database &db{settings.loadDatabase()};
_db = QSqlDatabase::addDatabase("QMYSQL", "my_database");
_db.setPort(3307);
_db.setHostName("localhost");
_db.setDatabaseName("test_db");
_db.setUserName(db.login);
_db.setPassword(db.password);
_db.open();
To copy to clipboard, switch view to plain text mode
Bookmarks