Files

59 lines
1.9 KiB
C++
Raw Permalink Normal View History

#ifndef SSHCLIENT_H
#define SSHCLIENT_H
#include <QObject>
2024-03-06 02:24:28 +01:00
#include <QFile>
#include <fcntl.h>
#include <libssh/libssh.h>
#include "defs.h"
using namespace amnezia;
2022-12-23 10:13:06 +03:00
namespace libssh {
2024-03-06 02:24:28 +01:00
enum ScpOverwriteMode {
/*! Overwrite any existing files */
2024-03-06 02:24:28 +01:00
ScpOverwriteExisting = O_TRUNC,
/*! Append new content if the file already exists */
2024-03-06 02:24:28 +01:00
ScpAppendToExisting = O_APPEND
};
2022-12-23 10:13:06 +03:00
class Client : public QObject
{
Q_OBJECT
public:
2024-03-06 02:24:28 +01:00
Client() = default;
~Client() = default;
ErrorCode connectToHost(const ServerCredentials &credentials);
void disconnectFromHost();
ErrorCode executeCommand(const QString &data,
const std::function<ErrorCode (const QString &, Client &)> &cbReadStdOut,
const std::function<ErrorCode (const QString &, Client &)> &cbReadStdErr);
ErrorCode writeResponse(const QString &data);
2024-03-06 02:24:28 +01:00
ErrorCode scpFileCopy(const ScpOverwriteMode overwriteMode,
2024-02-17 13:07:17 -08:00
const QString &localPath,
const QString &remotePath,
2024-03-06 02:24:28 +01:00
const QString &fileDesc);
ErrorCode getDecryptedPrivateKey(const ServerCredentials &credentials, QString &decryptedPrivateKey, const std::function<QString()> &passphraseCallback);
private:
ErrorCode closeChannel();
2024-03-06 02:24:28 +01:00
void closeScpSession();
ErrorCode fromLibsshErrorCode();
2024-03-06 02:24:28 +01:00
ErrorCode fromFileErrorCode(QFileDevice::FileError fileError);
static int callback(const char *prompt, char *buf, size_t len, int echo, int verify, void *userdata);
2023-02-01 09:56:55 +03:00
ssh_session m_session = nullptr;
ssh_channel m_channel = nullptr;
2024-03-06 02:24:28 +01:00
ssh_scp m_scpSession = nullptr;
static std::function<QString()> m_passphraseCallback;
signals:
void writeToChannelFinished();
2024-03-06 02:24:28 +01:00
void scpFileCopyFinished();
2022-12-23 10:13:06 +03:00
};
}
#endif // SSHCLIENT_H