1 Star 5 Fork 1

果冻粉gg/QFTP_Socket_Server

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
ftpretrcommand.cpp 1.42 KB
一键复制 编辑 原始数据 按行查看 历史
tuotq 提交于 2018-01-09 10:51 . v1.0
#include "ftpretrcommand.h"
#include <QFile>
#include <QTcpSocket>
FtpRetrCommand::FtpRetrCommand(QObject *parent, const QString &fileName, qint64 seekTo) :
FtpCommand(parent)
{
this->fileName = fileName;
this->seekTo = seekTo;
file = 0;
}
FtpRetrCommand::~FtpRetrCommand()
{
if (started) {
if (file && file->isOpen() && file->atEnd()) {
emit reply("226 Closing data connection.");
} else {
emit reply("550 Requested action not taken; file unavailable.");
}
}
}
void FtpRetrCommand::startImplementation()
{
file = new QFile(fileName, this);
if (!file->open(QIODevice::ReadOnly)) {
deleteLater();
return;
}
emit reply("150 File status okay; about to open data connection.");
if (seekTo) {
file->seek(seekTo);
}
// For encryted SSL sockets, we need to use the encryptedBytesWritten()
// signal, see the QSslSocket documentation to for reasons why.
//if (socket->isEncrypted()) {
// connect(socket, SIGNAL(encryptedBytesWritten(qint64)), this, SLOT(refillSocketBuffer(qint64)));
// } else {
connect(socket,&QTcpSocket::bytesWritten, this, &FtpRetrCommand::refillSocketBuffer);
// }
refillSocketBuffer(128*1024);
}
void FtpRetrCommand::refillSocketBuffer(qint64 bytes)
{
if (!file->atEnd()) {
socket->write(file->read(bytes));
} else {
socket->disconnectFromHost();
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/gmind31/QFTP_Socket_Server.git
git@gitee.com:gmind31/QFTP_Socket_Server.git
gmind31
QFTP_Socket_Server
QFTP_Socket_Server
master

搜索帮助