-
Notifications
You must be signed in to change notification settings - Fork 2
/
sftpclient.h
111 lines (77 loc) · 2.09 KB
/
sftpclient.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#ifndef SFTPCLIENT_H
#define SFTPCLIENT_H
#include <ctype.h>
#include <errno.h>
#include <fcntl.h>
#include <libssh2.h>
#include <libssh2_sftp.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <QDebug>
#include <QEventLoop>
#include <QObject>
#include <QString>
#include <QThread>
#include <iostream>
using namespace std;
#define BUFSIZE 32000
#ifdef WIN32
#pragma execution_character_set("utf-8")
#else
#include <arpa/inet.h>
#include <libgen.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
#include <sys/ioctl.h>
#include <unistd.h>
#endif
#include "connectinfo.h"
class SFTPClient : public QThread {
Q_OBJECT
public:
explicit SFTPClient(ConnectInfo connectInfo);
~SFTPClient();
bool connect();
bool openSession();
bool auth();
bool initSftpSession();
bool mkdir(QString path);
bool rmdir(QString path);
bool removeFile(QString path);
bool rename(QString sourceName, QString targetName);
// void fileDownload(QString remotePath, QString localPath);
void run();
void stop();
private:
ConnectInfo connectInfo;
int sock = 0;
struct sockaddr_in sin;
int rc = 0;
LIBSSH2_SESSION *session = NULL;
LIBSSH2_SFTP *sftp_session = NULL;
void close_connect();
public slots:
void scpUpload(QString filePath, QString remotePath);
void scpDownload(QString filePath, QString remotePath);
void opendir(QString sftpPath);
signals:
void asyncScpUpload(QString filePath, QString remotePath);
void asyncScpDownload(QString filePath, QString remotePath);
void asyncOpendir(QString sftpPath);
void errorMsg(QString msg);
void successMsg(QString msg);
void connectSuccess();
void authSuccess();
void opendirCallBack(QString data);
void opendirInfoCallBack(QString dirPath, QString data);
void initSftpSessionSuccess();
void fileUploadProcess(int fileSize, int currentSize, float process);
void fileUploadSuccess();
void fileDownloadProcess(int fileSize, int currentSize, float process);
void fileDownloadSuccess();
void opendirEvent(QString dirPath);
void disconnected();
};
#endif // SFTPCLIENT_H