QT5---FTP upload function (using a combination of methods to implement functions, Qnetworkaccessmanager Automatic management of multipart uploads, with qloggingcategory shielding SSL warning)

Source: Internet
Author: User
Tags git clone

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.