代码拉取完成,页面将自动刷新
#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();
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。