1

I want to download all the files of a directory in the server. So, I do:

_ftp->list("myDirectory/");

I connect the signal listInfo, and I implemented the slot like this:

void manageFTP::on_listInfo(QUrlInfo info) 
{
    if (!info.isDir())
    {
        QString remoteFile= "remote";
        QFile *file = new QFile(info.name());
        if (file ->open(QIODevice::ReadWrite))
            _ftp->get(remoteFile, file);
    }
}

My problem is to know when the download is entirely finished because I don't know how many files are in the directory and I don't know the id of the last get. How can I know and be sure the download has finished?

Charles
  • 50,943
  • 13
  • 104
  • 142
federem
  • 299
  • 1
  • 6
  • 17

1 Answers1

0

Your LIST and GET commands are scheduled and performed asynchronously. When the last pending command has finished QFtp emits a done(bool error) signal. So just connect a suitable slot to this signal before you execute the LIST command and you will be notified when all your commands have finished. Don't forget to disconnect the signal when done.

Daniel Hedberg
  • 5,677
  • 4
  • 36
  • 61
  • Is it not possible that the LIST command finished before the first GET command is scheduled? In this case, the signal `done` will be emitted whereas the download is not finished, won't it? – federem Jul 21 '13 at 20:10
  • 1
    I just had a quick look at the source code for QFtp and it seems like the listinfo() signal is triggered while the LIST command is being processed. This means that your on_listInfo() slot will be called and the GET commands will be queued for all directory entries before the LIST command finishes, i.e., all GET commands will be in the queue by this time and the done() signal will not be emitted until these have been processed. – Daniel Hedberg Jul 21 '13 at 21:05