If you are in a situation that you want to upload a file to a FTP server or delete, rename, copy some files on a FTP server in your Qt programs there are no definite choices anywhere. At least that is the case with Qt 5.5. You usually have to use a platform dependent library. So here it is. I use this library when I need FTP access in Qt for Windows. It uses Windows API therefore you won’t be able to use this in Linux or MAC. Download from the link provided below (you may have to register at codeproject.com) and follow the steps to be able to use it in your Qt programs.
1. Download FTP Client class files from here:
2. Extract all downloaded files to a folder named FtpClient under your project folder.
3. Add the headers and sources to your project by adding the following lines in your Qt PRO file:
SOURCES += FtpClient/BlockingSocket.cpp
HEADERS += FtpClient/BlockingSocket.h
4. Add Windows Sockets (Winsock) library to your project by adding the following line to your Qt PRO file:
LIBS += -lWs2_32
5. Include the main client class using the following line:
6. I would suggest you to take a look at the simple examples in the article provided for FtpClient. You can use modify and use them in Qt with very minor changes but anyway here is an example of uploading a file to an FTP server. First it tries to delete the existing file. (The same applies to download, rename or any other function.)
// connect to server
QMessageBox::critical(this, “Error”, “Can’t login!”);
// do file operations
QMessageBox::warning(this, “Warning”, “Can’t delete remote file!”);
QMessageBox::critical(this, “Error”, “Can’t upload!”);
QMessageBox::information(this, “Info”, “Finished!”);
Post a comment if you have any questions.