12,964
回編集
660行目: | 660行目: | ||
QString m_User; | QString m_User; | ||
QString m_Passwaord; | QString m_Passwaord; | ||
QString m_PubKey; | |||
QString m_PrivateKey; | |||
QString m_Passphrase; | |||
public: | public: | ||
SSHClient(QObject *parent = nullptr); | SSHClient(QString host, quint16 port, QString user, QString password, QObject *parent = nullptr); | ||
SSHClient(QString host, quint16 port, QString user, | |||
QString pubkey, QString privkey, QString phrase, QObject *parent = nullptr); | |||
~SSHClient(); | ~SSHClient(); | ||
void connectToHost(); | void connectToHost(); | ||
682行目: | 687行目: | ||
#include "SSHClient.h" | #include "SSHClient.h" | ||
SSHClient::SSHClient(QObject *parent = nullptr) : QObject(parent), | SSHClient::SSHClient(QString host, quint16 port, QString user, QString password, QObject *parent = nullptr) : | ||
QObject(parent), m_Session(nullptr), m_Channel(nullptr), m_Host(host), m_Port(port), m_User(user), m_Password(password) | |||
{ | |||
m_Socket = new QTcpSocket(this); | |||
connect(m_Socket, &QTcpSocket::connected, this, &SSHClient::onConnected); | |||
connect(m_Socket, &QTcpSocket::readyRead, this, &SSHClient::onReadyRead); | |||
// libSSH2ライブラリの初期化 | |||
if (libssh2_init(0) != 0) { | |||
qDebug() << "libSSH2ライブラリの初期化に失敗"; | |||
return; | |||
} | |||
} | |||
SSHClient::SSHClient(QString host, quint16 port, QString user, QString pubkey, QString privkey, QString phrase, QObject *parent = nullptr) : | |||
QObject(parent), m_Session(nullptr), m_Channel(nullptr), | |||
m_Host(host), m_Port(port), m_User(user), m_PublicKey(pubkey), m_PrivateKey(privkey), m_Passphrase(phrase) | |||
{ | { | ||
m_Socket = new QTcpSocket(this); | m_Socket = new QTcpSocket(this); | ||
736行目: | 757行目: | ||
do { | do { | ||
// パスワード認証を行う場合 | // パスワード認証を行う場合 | ||
rc = libssh2_userauth_password(m_Session, m_User, m_Password); | //rc = libssh2_userauth_password(m_Session, | ||
// m_User.toUtf8().constData(), | |||
// m_Password.toUtf8().constData()); | |||
// 公開鍵認証を行う場合 | |||
rc = libssh2_userauth_publickey_fromfile(m_Session, | |||
m_User.toUtf8().constData(), | |||
m_PubKey.toUtf8().constData(), | |||
m_PrivateKey.toUtf8().constData(), | |||
m_Passphrase.toUtf8().constData()); | |||
} while (rc == LIBSSH2_ERROR_EAGAIN); | } while (rc == LIBSSH2_ERROR_EAGAIN); | ||