00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #ifndef SSHCONNECTIONLIBSSH_H
00016 #define SSHCONNECTIONLIBSSH_H
00017
00018 #ifdef ENABLE_SSH
00019
00020 extern "C" {
00021 #include <libssh/libssh.h>
00022 #include <libssh/sftp.h>
00023 }
00024
00025 #include <globalsearch/sshconnection.h>
00026
00027 #include <globalsearch/sshmanager_libssh.h>
00028
00029 #include <QtCore/QObject>
00030 #include <QtCore/QString>
00031 #include <QtCore/QMutex>
00032
00033 #define LIBSSH_BUFFER_SIZE 20480
00034
00035 namespace GlobalSearch {
00036
00047 class SSHConnectionLibSSH : public SSHConnection
00048 {
00049 Q_OBJECT
00050
00051 public:
00052
00058 explicit SSHConnectionLibSSH(SSHManagerLibSSH *parent = 0);
00059
00063 virtual ~SSHConnectionLibSSH();
00064
00065 public slots:
00067 void setUsed(bool b) {m_inUse = b;};
00068
00070 bool inUse() {return m_inUse;};
00071
00082 bool execute(const QString &command,
00083 QString &stdout_str,
00084 QString &stderr_str,
00085 int &exitcode);
00086
00095 bool copyFileToServer(const QString & localpath,
00096 const QString & remotepath);
00097
00106 bool copyFileFromServer(const QString & remotepath,
00107 const QString & localpath);
00108
00118 bool readRemoteFile(const QString &filename,
00119 QString &contents);
00120
00128 bool removeRemoteFile(const QString &filename);
00129
00138 bool copyDirectoryToServer(const QString & localpath,
00139 const QString & remotepath);
00140
00149 bool copyDirectoryFromServer(const QString & remotepath,
00150 const QString & localpath);
00151
00160 bool readRemoteDirectoryContents(const QString & remotepath,
00161 QStringList & contents);
00162
00172 bool removeRemoteDirectory(const QString & remotepath,
00173 bool onlyDeleteContents = false);
00174
00175
00177 bool isValid() {return m_isValid;};
00178
00180 bool isConnected();
00181
00191 bool connectSession(bool throwExceptions = false);
00192
00199 bool reconnectSession(bool throwExceptions = false);
00200
00206 bool disconnectSession();
00207
00214 bool reconnectIfNeeded() {if (!isConnected()) return reconnectSession(false);
00215 return true;};
00216
00225 static bool addKeyToKnownHosts(const QString &host, unsigned int port = 22);
00226
00227 signals:
00233 void unknownHostKey(const QString &hexa);
00234
00235 protected:
00236
00238 sftp_session _openSFTP();
00239 bool _execute(const QString &command,
00240 QString &stdout_err,
00241 QString &stderr_err,
00242 int &exitcode);
00243 bool _copyFileToServer(const QString & localpath,
00244 const QString & remotepath);
00245 bool _copyFileFromServer(const QString & remotepath,
00246 const QString & localpath);
00247 bool _readRemoteFile(const QString &filename,
00248 QString &contents);
00249 bool _removeRemoteFile(const QString &filename);
00250 bool _copyDirectoryToServer(const QString & localpath,
00251 const QString & remotepath);
00252 bool _copyDirectoryFromServer(const QString & remotepath,
00253 const QString & localpath);
00254 bool _readRemoteDirectoryContents(const QString & remotepath,
00255 QStringList & contents);
00256 bool _removeRemoteDirectory(const QString & remotepath,
00257 bool onlyDeleteContents = false);
00258
00259 ssh_session m_session;
00260 ssh_channel m_shell;
00261
00262 bool m_isValid;
00263 bool m_inUse;
00264 QMutex m_lock;
00265
00266
00268 };
00269
00270 }
00271
00272
00273 #endif // ENABLE_SSH
00274 #endif // SSHCONNECTIONLIBSSH_H