|
Packit |
01d647 |
// ***************************************************************** -*- C++ -*-
|
|
Packit |
01d647 |
/*
|
|
Packit |
01d647 |
* Copyright (C) 2004-2018 Exiv2 authors
|
|
Packit |
01d647 |
* This program is part of the Exiv2 distribution.
|
|
Packit |
01d647 |
*
|
|
Packit |
01d647 |
* This program is free software; you can redistribute it and/or
|
|
Packit |
01d647 |
* modify it under the terms of the GNU General Public License
|
|
Packit |
01d647 |
* as published by the Free Software Foundation; either version 2
|
|
Packit |
01d647 |
* of the License, or (at your option) any later version.
|
|
Packit |
01d647 |
*
|
|
Packit |
01d647 |
* This program is distributed in the hope that it will be useful,
|
|
Packit |
01d647 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit |
01d647 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
Packit |
01d647 |
* GNU General Public License for more details.
|
|
Packit |
01d647 |
*
|
|
Packit |
01d647 |
* You should have received a copy of the GNU General Public License
|
|
Packit |
01d647 |
* along with this program; if not, write to the Free Software
|
|
Packit |
01d647 |
* Foundation, Inc., 51 Franklin Street, 5th Floor, Boston, MA 02110-1301 USA.
|
|
Packit |
01d647 |
*/
|
|
Packit |
01d647 |
#ifndef SSH_HPP_
|
|
Packit |
01d647 |
#define SSH_HPP_
|
|
Packit |
01d647 |
|
|
Packit |
01d647 |
// included header files
|
|
Packit |
01d647 |
#include "config.h"
|
|
Packit |
01d647 |
|
|
Packit |
01d647 |
#ifdef EXV_USE_SSH
|
|
Packit |
01d647 |
#include <libssh/libssh.h>
|
|
Packit |
01d647 |
#include <libssh/sftp.h>
|
|
Packit |
01d647 |
#include <sys/stat.h>
|
|
Packit |
01d647 |
#include <string>
|
|
Packit |
01d647 |
|
|
Packit |
01d647 |
#include "error.hpp"
|
|
Packit |
01d647 |
#include "types.hpp"
|
|
Packit |
01d647 |
#include "futils.hpp"
|
|
Packit |
01d647 |
|
|
Packit |
01d647 |
namespace Exiv2 {
|
|
Packit |
01d647 |
/*!
|
|
Packit |
01d647 |
@brief The class provides the high-level functions related to libssh.
|
|
Packit |
01d647 |
It makes the libssh transparent. The functions in this class can
|
|
Packit |
01d647 |
be used without the requirement of understanding libssh.
|
|
Packit |
01d647 |
*/
|
|
Packit |
01d647 |
class EXIV2LIB_DEPRECATED_EXPORT SSH {
|
|
Packit |
01d647 |
public:
|
|
Packit |
01d647 |
//! @name Creators
|
|
Packit |
01d647 |
//@{
|
|
Packit |
01d647 |
/*!
|
|
Packit |
01d647 |
@brief Constructor to set up the connection to ssh server.
|
|
Packit |
01d647 |
@param host The host name of ssh server.
|
|
Packit |
01d647 |
@param user The username used to connect to ssh server.
|
|
Packit |
01d647 |
@param pass The password used to connect to ssh server.
|
|
Packit |
01d647 |
@param port The port to connect to ssh server. Set empty string to use the default port.
|
|
Packit |
01d647 |
@throw Error if it fails to connect the server.
|
|
Packit |
01d647 |
*/
|
|
Packit |
01d647 |
SSH (const std::string& host, const std::string& user, const std::string& pass, const std::string port = "");
|
|
Packit |
01d647 |
//! Destructor
|
|
Packit |
01d647 |
~SSH();
|
|
Packit |
01d647 |
//@}
|
|
Packit |
01d647 |
|
|
Packit |
01d647 |
//! @name Manipulators
|
|
Packit |
01d647 |
//@{
|
|
Packit |
01d647 |
/*!
|
|
Packit |
01d647 |
@brief Run the command on the remote machine.
|
|
Packit |
01d647 |
@param cmd The command
|
|
Packit |
01d647 |
@param output The container for the command's output
|
|
Packit |
01d647 |
@return 0 (SSH_OK) if there is no error.
|
|
Packit |
01d647 |
*/
|
|
Packit |
01d647 |
int runCommand(const std::string& cmd, std::string* output);
|
|
Packit |
01d647 |
/*!
|
|
Packit |
01d647 |
@brief SCP data to the remote machine.
|
|
Packit |
01d647 |
@param filePath The path of the new file on the remote machine where the data is saved.
|
|
Packit |
01d647 |
@param data The data copied to the remote machine.
|
|
Packit |
01d647 |
@param size The size of the data.
|
|
Packit |
01d647 |
@return 0 (SSH_OK) if there is no error.
|
|
Packit |
01d647 |
@throw Error if it is unable to copy the data.
|
|
Packit |
01d647 |
*/
|
|
Packit |
01d647 |
int scp(const std::string& filePath, const byte* data, size_t size);
|
|
Packit |
01d647 |
/*!
|
|
Packit |
01d647 |
@brief Return the sftp file handle of the file on the remote machine to read the data.
|
|
Packit |
01d647 |
@param filePath The path of the file on the remote machine.
|
|
Packit |
01d647 |
@param handle The container for the file handle.
|
|
Packit |
01d647 |
@throw Error if it is unable to get the sftp file handle.
|
|
Packit |
01d647 |
|
|
Packit |
01d647 |
@note Be sure to close() the file handle after use.
|
|
Packit |
01d647 |
*/
|
|
Packit |
01d647 |
void getFileSftp(const std::string& filePath, sftp_file& handle);
|
|
Packit |
01d647 |
//@}
|
|
Packit |
01d647 |
private:
|
|
Packit |
01d647 |
/*!
|
|
Packit |
01d647 |
@brief Open the sftp session.
|
|
Packit |
01d647 |
*/
|
|
Packit |
01d647 |
void openSftp();
|
|
Packit |
01d647 |
// DATA
|
|
Packit |
01d647 |
//! The number of seconds to wait while trying to connect.
|
|
Packit |
01d647 |
long timeout_;
|
|
Packit |
01d647 |
//! the ssh server host
|
|
Packit |
01d647 |
std::string host_;
|
|
Packit |
01d647 |
//! the username
|
|
Packit |
01d647 |
std::string user_;
|
|
Packit |
01d647 |
//! the password
|
|
Packit |
01d647 |
std::string pass_;
|
|
Packit |
01d647 |
//! the ssh session
|
|
Packit |
01d647 |
ssh_session session_;
|
|
Packit |
01d647 |
//! the sftp session
|
|
Packit |
01d647 |
sftp_session sftp_;
|
|
Packit |
01d647 |
}; // class SSH
|
|
Packit |
01d647 |
} // namespace Exiv2
|
|
Packit |
01d647 |
#endif
|
|
Packit |
01d647 |
|
|
Packit |
01d647 |
#endif // #ifdef EXIV2_HPP_
|