我目前面临一个关于 QFtp 的奇怪问题。我想从 FTP 服务器下载一堆文件,但是当我到达某个点时,在 y 上下载 x 文件后,ftp->get()
命令完成,文件被填充,但没有发射,SIGNAL
commandFinished()
因此它不下载其他文件。
这是我的代码:
void Ftp::commandFinished(int i, bool error)
{
if(ftp->currentCommand() == QFtp::Get)
{
if(error)
{
//blablabla-ERROR-blablabla
}
currentFile->close();
filesToDownload.pop_front();
processFileList();
}
/**Gestion de la commande Login (authentification de l'utilisateur)
*/
if(ftp->currentCommand() == QFtp::Login)
{//not utile here}
/**Gestion de la commande ConnectToHost (connexion au serveur)
*/
if (ftp->currentCommand() == QFtp::ConnectToHost)
{//not utile here}
/**Gestion de la commande List (téléchargement d'un fichier)
*/
if(ftp->currentCommand() == QFtp::List)
{
if(error)
{
//Nananana-FAIL-nanana
}
//!Tri des fichiers à télécharger en fonction de leur dernière date de modification
if (!filesToDownload.isEmpty())
{
currentPeripheral->setLastDownloadDate(newLastModifiedDate) ;
std::sort(filesToDownload.begin(),filesToDownload.end(),compareQUrlInfos);
processFileList();
}
}
}
void Ftp::processFileList()
{
QUrlInfo info;
if (filesToDownload.isEmpty())
{
//!Suicide de l'instance de Ftp
ftp->close();
disconnect(this,0,0,0);
this->deleteLater();
return ;
}
info = filesToDownload.first();
QDir dlDir(QString::number(currentPeripheral->getId()));
//!Si un fichier a été téléchargé, on déclenche son traitement
if (currentFile != nullptr)
{
emit(oneDownloadFinished(currentFile->fileName(),currentPeripheral));
delete currentFile;
currentFile = nullptr;
}
//!On crée un répertoire de téléchargement si nécessaire
if (!dlDir.exists())
{
dlDir.mkdir(".");
}
//!on crée le fichier qui contiendra le téléchargement
currentFile = new QFile(dlDir.filePath(info.name()));
if(!currentFile->open(QIODevice::WriteOnly))
{
delete currentFile;
currentFile = nullptr;
emit(writeToMonitoringConsole(QString("Erreur lors de la creation du fichier "+info.name()),"Error"));
return;
}
//Here I start (sometimes) a never ending fail
ftp->get(info.name(), currentFile);
}
起初我以为是因为我提出了太多要求,因此我被拒绝了,但即使有一个Sleep(2000)
it 块。阻塞出现得更快。我通常可以下载大约 30 个文件(幸运的是 70 个,一旦我设法拥有 200 个!)。我Sleep(2000)
几乎没有成功下载2-3个文件。
这是我的错吗?我没有发现 QFtp 有限制吗?或者是其他东西 ?
编辑:自从我发布它以来,我测试了一些东西,当监控 dataTransferProgress() 信号时,引人注目的是有问题的文件已完全下载(qDebug 说“88928/88928”),但我从未输入 commandFinished()。
我的插槽 commandFinished() 以这种方式链接到我的 QFtp::commandFinished SIGNAL :
connect(ftp, SIGNAL(commandFinished(int,bool)), this, SLOT(commandFinished(int,bool)));