2015-04-13 16:48:41 -04:00
|
|
|
/**
|
2015-04-06 15:42:05 -04:00
|
|
|
* File: SFTP.h
|
|
|
|
* Author: twarren
|
|
|
|
*
|
|
|
|
* Created on April 6, 2015, 2:22 PM
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef SFTP_H
|
|
|
|
#define SFTP_H
|
|
|
|
|
2015-07-02 15:05:05 -04:00
|
|
|
#include "../common.h"
|
2015-04-06 15:42:05 -04:00
|
|
|
|
|
|
|
// Socket includes
|
|
|
|
#include <cstring>
|
2015-04-08 11:13:26 -04:00
|
|
|
|
2015-04-08 19:39:53 -04:00
|
|
|
#ifdef WIN32
|
2015-04-14 13:49:06 -04:00
|
|
|
// Define this so I actually get functions out of the windows header file
|
2015-04-22 21:06:35 -04:00
|
|
|
#undef _WIN32_WINNT
|
2015-04-14 13:49:06 -04:00
|
|
|
#define _WIN32_WINNT 0x0501
|
2015-06-24 14:12:05 -04:00
|
|
|
#include <winsock2.h>
|
|
|
|
#include <ws2tcpip.h>
|
2015-04-08 11:13:26 -04:00
|
|
|
#else
|
2015-06-24 14:12:05 -04:00
|
|
|
#include <sys/types.h>
|
2015-04-08 11:13:26 -04:00
|
|
|
#include <sys/socket.h>
|
2015-04-08 19:39:53 -04:00
|
|
|
#include <netdb.h>
|
2015-04-08 11:13:26 -04:00
|
|
|
#endif
|
|
|
|
|
2015-04-07 20:19:05 -04:00
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
// libssh2 includes
|
|
|
|
#include <libssh2.h>
|
|
|
|
#include <libssh2_sftp.h>
|
2015-04-06 15:42:05 -04:00
|
|
|
|
|
|
|
class SFTP {
|
|
|
|
public:
|
2015-06-24 14:12:05 -04:00
|
|
|
SFTP(const char *host, const char *user, const char *pass, const char *base_path="~", const char *port="22");
|
2015-04-06 15:42:05 -04:00
|
|
|
~SFTP();
|
2015-04-08 11:06:24 -04:00
|
|
|
string getFingerprint();
|
2015-04-07 17:08:28 -04:00
|
|
|
string getFile(const char *path);
|
2015-06-24 14:12:05 -04:00
|
|
|
bool createDir(const char *path);
|
|
|
|
bool writeFile(const char *path, const char *data);
|
|
|
|
//StringVector getDirList(const char *path);
|
2015-04-06 15:42:05 -04:00
|
|
|
private:
|
2015-04-07 17:08:28 -04:00
|
|
|
struct addrinfo host_info;
|
2015-06-24 14:12:05 -04:00
|
|
|
struct addrinfo *host_info_list = nullptr;
|
2015-04-07 17:08:28 -04:00
|
|
|
const char *fingerprint;
|
|
|
|
int sock;
|
2015-06-24 14:12:05 -04:00
|
|
|
LIBSSH2_SESSION *session = nullptr;
|
|
|
|
LIBSSH2_SFTP *sftp_session = nullptr;
|
|
|
|
void create_socket(const char *host, const char *port);
|
|
|
|
void destroy_socket();
|
|
|
|
void ssh_connect();
|
2015-04-07 17:08:28 -04:00
|
|
|
void sftp_connect();
|
2015-04-06 15:42:05 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* SFTP_H */
|
|
|
|
|