As you can see from the version evolution of Qt, the Qftp class in QT4 is no longer available in Qt5, although it is possible to compile qftp by itself in Qt5, but the QT5 provides QNetworkAccessManager
better compatibility and extensibility in sending and requesting networks, including FTP requests and HTTP requests.
Here is a way to get the source of qftp in QT4:
git clone git://code.qt.io/qt/qtftp.gitgit clone http://code.qt.io/qt/qtftp.gitgit clone https://code.qt.io/qt/qtftp.git
The following FTP upload work is implemented in the case of a password and no password to upload:
#include<qtcore>#include<qtnetwork>#include<qdebug>class Uploader:Public qobject{Q_objectPublic:uploader (Qobject*p=0): Qobject (P) {}void Start (const QString&file) {No passwdQurl URL ("Ftp://172.20.5.167/ftp.txt"); Qurl URL; Url. SetScheme ("FTP"); Url. Sethost ("172.20.5.167");Here is the file name to set when the remote host uploads, not set the name to the local upload name URL. SetPath ("/ftp.txt"); Url. Setusername ("Root"); Url. Setport (21);Need passwd/* Qurl URL ("Ftp://172.20.5.167/ftp.txt"); Url.setscheme ("ftp"); Url.setusername ("root"); Url.setport (21); */Data=New QFile (file, this);if (Data->open (Qiodevice:: ReadOnly)) {reply= Nam. put (qnetworkrequest (URL),data); Connect (reply, SIGNAL (uploadprogress (Qint64, Qint64)), SLOT (Uploadprogress (Qint64, Qint64))); Connect (reply, SIGNAL (finished ()), SLOT (Uploaddone ())); }else Qdebug ()<<"Oops"; }Public Slots:void Uploadprogress (Qint64 bytessent, Qint64 bytestotal) {qdebug ()<<"uploaded"<< BytesSent<<"Of"<< Bytestotal; }void Uploaddone () {qdebug ()<<"Finished"<< reply->error ();data->deletelater (); Reply- >deletelater (); }private:qnetworkaccessmanager nam; QFile *data; Qnetworkreply *reply;}; int main (int argc, char **argv) {qcoreapplication app (argc, argv); //remove FTP upload network.ssl warning Qloggingcategory::setfilterrules ( Span class= "hljs-string" > "Qt.network.ssl.warning=false"); Uploader u; U.start (QString (return app.exec (); //compile without missing the following sentence #include
Above program main notice place is local side upload file and host side file, understand Qurl (no password for ftp://[email protected]: 21):
Ensure that each part of the FTP address is set in place.
http://blog.csdn.net/freeape/article/details/52802163
QT5---FTP upload function (using a combination of methods to implement functions, Qnetworkaccessmanager Automatic management of multipart uploads, with qloggingcategory shielding SSL warning)