玉兔远程控制
0.1.0-bate11
Toggle main menu visibility
载入中...
搜索中...
未找到
Plugins
FileTransfer
ChannelSFTP.h
1
// Copyright Copyright (c) Kang Lin studio, All Rights Reserved
2
// Author: Kang Lin <kl222@126.com>
3
4
#pragma once
5
#include "ChannelSSH.h"
6
#include "libssh/sftp.h"
7
#include <QDateTime>
8
9
#define BUF_SIZE 4096
10
11
class
CRemoteFileSystem
;
12
class
CFileTransfer
;
13
class
CChannelSFTP :
public
CChannelSSH
14
{
15
Q_OBJECT
16
17
public
:
18
explicit
CChannelSFTP(
CBackend
* pBackend,
CParameterSSH
* pPara,
19
bool
bWakeUp =
true
, QObject *parent =
nullptr
);
20
26
int
GetDir
(
CRemoteFileSystem
* p);
27
int
MakeDir(
const
QString& dir);
28
int
RemoveDir(
const
QString& dir);
29
int
RemoveFile(
const
QString& file);
30
int
Rename(
const
QString& oldPath,
const
QString& newPath);
31
32
int
Process();
33
34
public
Q_SLOTS:
38
void
slotGetDir
(
const
QString& szPath,
CRemoteFileSystem
*p);
39
Q_SIGNALS:
40
void
sigGetDir(
CRemoteFileSystem
* p, QVector<QSharedPointer<CRemoteFileSystem> > contents,
bool
bEnd);
41
42
public
Q_SLOTS:
43
void
slotStartFileTransfer(QSharedPointer<CFileTransfer> f);
44
void
slotStopFileTransfer(QSharedPointer<CFileTransfer> f);
45
Q_SIGNALS:
46
void
sigFileTransferUpdate(QSharedPointer<CFileTransfer> f);
47
48
protected
:
49
virtual
qint64 readData(
char
*data, qint64 maxlen)
override
;
50
virtual
qint64 writeData(
const
char
*data, qint64 len)
override
;
51
52
private
:
53
enum class
STATE {
54
OPEN,
55
READ,
56
CLOSE,
57
FINISH,
58
ERR
59
};
60
struct
DIR_READER
{
61
sftp_dir sftp;
62
QString szPath;
63
STATE state;
64
CRemoteFileSystem
* remoteFileSystem;
65
QVector<QSharedPointer<CRemoteFileSystem> > vFileNode;
66
int
Error;
67
};
68
69
#if LIBSSH_VERSION_INT >= SSH_VERSION_INT(0, 11, 0)
70
struct
_AIO
{
71
sftp_aio aio;
72
quint64 nStart;
73
quint64 nRequests;
74
quint64 nTransfers;
75
char
* buffer;
76
};
77
#endif
78
79
struct
_AFILE
{
80
sftp_file remote;
81
int
local;
82
STATE state;
83
QSharedPointer<CFileTransfer> fileTransfer;
84
85
#if LIBSSH_VERSION_INT >= SSH_VERSION_INT(0, 11, 0)
86
QVector<sftp_aio> aio;
87
// The chunk size to use for the transfer
88
quint64 nChunkSize;
89
int
nConcurrentCount;
90
#else
91
int
asyncReadId;
92
#endif
93
quint64 nRequests;
94
quint64 nTransfers;
95
char
*buffer;
96
97
};
98
99
virtual
int
OnOpen(ssh_session session)
override
;
100
virtual
void
OnClose()
override
;
101
QSharedPointer<CRemoteFileSystem> GetFileNode(
const
QString &szPath, sftp_attributes attributes);
102
int
AsyncReadDir();
103
int
AsyncFile();
104
int
CleanFileAIO(QSharedPointer<_AFILE> aio);
105
106
private
:
107
sftp_session m_SessionSftp;
108
QVector<QSharedPointer<DIR_READER> > m_vDirs;
109
QVector<QSharedPointer<_AFILE> > m_vFiles;
110
};
CBackend
后端接口。它由协议插件实现。 它默认启动一个定时器来开启一个非 Qt 事件循环(就是普通的循环处理)。 详见: Start()、 slotTimeOut()、 OnProcess() 。 当然,它仍然支...
定义
Backend.h:52
CChannelSFTP::GetDir
int GetDir(CRemoteFileSystem *p)
Synchronize to get the directory
定义
ChannelSFTP.cpp:142
CChannelSFTP::slotGetDir
void slotGetDir(const QString &szPath, CRemoteFileSystem *p)
Get the directory asynchronously
定义
ChannelSFTP.cpp:380
CFileTransfer
定义
ListFileModel.h:11
CParameterSSH
定义
ParameterSSH.h:8
CRemoteFileSystem
定义
RemoteFileSystemModel.h:10
CChannelSFTP::DIR_READER
定义
ChannelSFTP.h:60
CChannelSFTP::_AFILE
定义
ChannelSFTP.h:79
CChannelSFTP::_AIO
定义
ChannelSFTP.h:70
作者:康林 (kl222@126.com)
版权所有(c) 康林工作室 保留所有权力