#ifndef SSHCLIENT_H #define SSHCLIENT_H #include #include #include #include #include "defs.h" using namespace amnezia; namespace libssh { enum SftpOverwriteMode { /*! Overwrite any existing files */ SftpOverwriteExisting = O_TRUNC, /*! Append new content if the file already exists */ SftpAppendToExisting = O_APPEND }; class Client : public QObject { Q_OBJECT public: Client(QObject *parent = nullptr); ~Client(); ErrorCode connectToHost(const ServerCredentials &credentials); void disconnectFromHost(); ErrorCode executeCommand(const QString &data, const std::function &cbReadStdOut, const std::function &cbReadStdErr); ErrorCode writeResponse(const QString &data); ErrorCode sftpFileCopy(const SftpOverwriteMode overwriteMode, const std::string& localPath, const std::string& remotePath, const std::string& fileDesc); private: ErrorCode closeChannel(); ErrorCode closeSftpSession(); ErrorCode fromLibsshErrorCode(int errorCode); ErrorCode fromLibsshSftpErrorCode(int errorCode); ssh_session m_session {}; ssh_channel m_channel {}; sftp_session m_sftpSession {}; signals: void writeToChannelFinished(); void sftpFileCopyFinished(); }; } #endif // SSHCLIENT_H