#ifndef __WIN_SSH2_20200506__ #define __WIN_SSH2_20200506__ #include "libssh2_config.h" #include "libssh2.h" #include "libssh2_sftp.h" #include #pragma comment(lib, "ws2_32.lib") #pragma once #define SHUTDOWN(session, sock) \ libssh2_session_disconnect(session, "Normal Shutdown, Thank you for playing");\ libssh2_session_free(session);\ closesocket(sock);\ libssh2_exit(); class CWinSsh2Proc { public: CWinSsh2Proc(void); ~CWinSsh2Proc(void); private: int m_port; std::string m_host; std::string m_user; std::string m_pwd; sockaddr_in m_sin; void ssh2_read_channel(LIBSSH2_CHANNEL* pChannel, std::string &buffer); bool ssh2_init_session(LIBSSH2_SESSION** pSession, SOCKET &sock); void ssh2_free(LIBSSH2_SESSION* pSession, LIBSSH2_CHANNEL* pChannel); public: static bool InitSocket(); static int waitsocket(int socket_fd, LIBSSH2_SESSION *session); bool ssh2_connect(std::string host, std::string user, std::string pwd, int port = 22); void ssh2_disconnect(); bool ssh2_execute_command(std::string cmd, std::string &result, DWORD dwTimeout = 1000); bool ssh2_sftp_download(std::string sftppath, std::string localpath); }; #endif //__WIN_SSH2_20200506__