Displaying the file list

Next, we will learn how to save and display the file list on the FTP server. Actually, the FTP server does provide the file list by default, and Qt was able to display it using the qtftp module back in older versions. However, since Version 5, Qt has completely dropped the qtftp module and this feature no longer exists.

If you're still interested in the old qtftp module, you can still obtain its source code on GitHub by visiting the following link: https://github.com/qt/qtftp

In Qt, we use the QNetworkAccessManager class to communicate with our FTP server so features that are specifically designed for FTP no longer work. But, don't worry, we will look into some other alternative methods to achieve the same result.

The best method, in my opinion, is using an online database to store the file list and its information (file size, format, status, and so on). If you're interested in learning how to connect your Qt application to a database, please refer to Chapter 3, Database Connection. However, for the sake of simplicity, we will use another method that works just fine but is less secure—by saving the file names directly on a text file and storing it on the FTP server.

If you're doing a serious project for your client or company, please do not use this method. Check out Chapter 3Database Connection, and learn to use an actual database instead.

Alright, just assume that there is no other way but to use the text file; how are we going to do that? It's very simple: create a text file called files.txt and place it into the FTP directory we just created at the very beginning of this chapter.