Question

I am actually wanting to get the newest files from a ftp server. For this, I am currently using QFtp to access the server and retrieve what I need.

This is what I do (like every 3 minutes) :

  • Connection & authentification to the server.

  • list() command to list all the files.

  • for each file listed by the list() command I call a slot that verify if the file currently listed has not been already downloaded (I am relying on the date of the file). If the file is recent enough, I download it.

So, it works. But it it really slow because there are thousands of files on the server and each time I verify the date of each of them. Is it possible to abort the list() command for example when I find a file too old ? Or is there another smarter way to fasten the process ?

Was it helpful?

Solution

Yes, there is a way to abort the long-playing command. When you call QFtp::list() it starts execution command on Ftp server, and if command finds an entry, QFtp emits QFtp::listInfo(const QUrlInfo &) signal. You can handle that signal, and check, whether the QUrlInfo::lastModified() returned time is too old. If yes, you can call QFtp::abort() function to abort the list command's execution on the server. Here is the sample code:

Establish connection to handle the ftp signals

connect(ftp, SIGNAL(listInfo(const QUrlInfo &)),
        this, SLOT(onNewEntry(const QUrlInfo &)));

Implementation of the listInfo signal handling slot:

void MyFtp::onNewEntry(const QUrlInfo &url)
{
    // If url.lastModified() is less than some time
    // ftp->abort();    
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top