-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsftpmanager.h
More file actions
71 lines (64 loc) · 2.27 KB
/
sftpmanager.h
File metadata and controls
71 lines (64 loc) · 2.27 KB
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
#ifndef SFTPMANAGER_H
#define SFTPMANAGER_H
#include <QObject> //信号与槽;元对象系统;父子对象树与内存管理;MainWindow和SftpManager都继承自QObject,以便能够使用信号和槽进行通信
#include <QString>
#include <libssh2.h>
#include <libssh2_sftp.h>
#include <QList>
#include <QDateTime>
#ifdef WIN32
#include <winsock2.h>
#else
#include <sys/socket.h>
#endif
//用一个结构体来表示一个远程文件地信息
struct RemoteFile{
QString name;
quint64 size;
QString permissionsString; //权限
uint ownerId;
uint groupId;
QDateTime modificationTime;
bool isDirectory;
};
class SftpManager : public QObject
{
Q_OBJECT
public:
explicit SftpManager(QObject *parent = nullptr);
~SftpManager();
//槽
public slots:
void connectToHost(const QString &host,int port ,const QString &user,const QString &pass);//连接函数
void listDirectory(const QModelIndex &parentIndex,const QString &path);
//新增:接收下载文件请求的槽
void downloadFile(const QString &remotePath , const QString &localPath);
// 新增:接收上传文件请求的槽
void uploadFile(const QString &localPath, const QString &remotePath);
// 新增:接收删除文件请求的槽
void deleteRemoteFile(const QString &remotePath);
//信号
signals:
void connected(); //用于回报信号
void error(const QString &message);
void directoryListed(const QModelIndex &parentIndex, const QList<RemoteFile> &files);
// 新增:汇报进度的信号
void transferProgress(qint64 bytesTransferred, qint64 totalBytes);
// 新增:通知下载完成的信号
void downloadFinished(const QString &remotePath, const QString &localPath, qint64 size, bool success, const QString &errorMessage);
// 新增:通知上传完成的信号
void uploadFinished(const QString &localPath, const QString &remotePath,qint64 size, bool success, const QString &errorMessage);
// 新增:通知删除完成的信号
void remoteFileDeleted(const QString &remotePath, bool success, const QString &errorMessage);
private:
#ifdef WIN32
SOCKET m_socket;
#else
int m_socket;
#endif
//LIBSSH2_SESSION 代表一个SSH会话的句柄
LIBSSH2_SESSION *m_session;//声明一个m_session的指针,指向一个LIBSSH2——SEEION对象
// LIBSSH2_SFTP 代表一个SFTP会话的句柄
LIBSSH2_SFTP *m_sftpSession;//声明一个m_sftpSession的指针,指向一个LIBSSH2_SFTP对象
};
#endif // SFTPMANAGER_H