You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
95 lines
2.4 KiB
C++
95 lines
2.4 KiB
C++
#ifndef SFTP_H_INCLUDED
|
|
#define SFTP_H_INCLUDED
|
|
#include "HTPublic.h"
|
|
#include "HTType.h"
|
|
#include <list>
|
|
#include "libssh2.h"
|
|
#include "libssh2_sftp.h"
|
|
#include "libssh2_publickey.h"
|
|
#include "openssl/des.h"
|
|
#include "openssl/sha.h"
|
|
#include "openssl/md5.h"
|
|
#include <string>
|
|
|
|
//#include "SSH.h"
|
|
#pragma pack (push ,1)
|
|
#pragma comment(lib,"libssh2.lib")
|
|
//#pragma comment(lib,"libeay32.lib")
|
|
//#pragma comment(lib,"ssleay32.lib")
|
|
#pragma comment(lib,"ws2_32.lib")
|
|
#pragma comment(lib,"crypt32.lib")
|
|
|
|
using namespace std;
|
|
typedef struct
|
|
{
|
|
int iFileSize;
|
|
char szFileName[256];
|
|
}ST_FILES_LIST;
|
|
#pragma pack (pop)
|
|
|
|
class SSH {
|
|
private:
|
|
string ip;
|
|
unsigned short port;
|
|
int sock;
|
|
|
|
SSH(const SSH&);
|
|
SSH& operator=(const SSH&);
|
|
|
|
public:
|
|
bool connected;
|
|
void* session;
|
|
|
|
bool connectTo(const string&, const string&);
|
|
void disconnect(void);
|
|
public:
|
|
SSH(string, unsigned short);
|
|
virtual ~SSH(void);
|
|
|
|
virtual bool openSession(const string&, const string&) = 0;
|
|
virtual void closeSession(void) = 0;
|
|
};
|
|
|
|
|
|
class SFTP : public SSH {
|
|
private:
|
|
void* sftpSession;
|
|
char m_LastErrMsg[128];
|
|
|
|
SFTP(const SFTP&);
|
|
SFTP& operator=(const SFTP&);
|
|
public:
|
|
|
|
SFTP(string, unsigned short = 22);
|
|
virtual ~SFTP(void);
|
|
|
|
virtual bool openSession(const string&, const string&);
|
|
virtual void closeSession(void);
|
|
char *getLastErrMsg();
|
|
|
|
bool exists(const string&) const;
|
|
utint64 size(const string&) const;
|
|
utint64 sizeEx(const void*) const;
|
|
void* open(const string&, const unsigned int) const;
|
|
void seek(const void*, const utint64) const;
|
|
long read(const void*, char*, const unsigned int) const;
|
|
long write(const void*, const char*, const unsigned int) const;
|
|
int close(const void*) const;
|
|
bool mkdir(const string&) const;
|
|
void rmdir(const string&) const;
|
|
list<ST_FILES_LIST> ls(const string& = "./", const unsigned int = FILTER_FILE | FILTER_PATH | FILTER_LONG) const;
|
|
void rm(const string&) const;
|
|
bool rename(const string&, const string&) const;
|
|
int download(const char* remoteFile, const char* localPath, int &error);
|
|
|
|
static const unsigned int READ;
|
|
static const unsigned int WRITE;
|
|
static const unsigned int CREATE;
|
|
|
|
static const unsigned int FILTER_FILE;
|
|
static const unsigned int FILTER_PATH;
|
|
static const unsigned int FILTER_LONG;
|
|
};
|
|
#endif // SFTP_H_INCLUDED
|
|
|