123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- #ifndef QTFTP_H
- #define QTFTP_H
- #include <QObject>
- #include <QNetworkReply>
- #include <QNetworkAccessManager>
- #include <QUrl>
- #include <QFile>
- #include <QTimer>
- class QtFtp : public QObject
- {
- Q_OBJECT
- public:
- explicit QtFtp(QObject* parent = nullptr);
- ~QtFtp();
-
- void setHostAndPort(const QString& host,int port = 21);
-
- void setUserPasswd(const QString& user,const QString& pw);
-
- void putFile(const QString& fileName,const QString& farPath);
-
- void putFile(const QByteArray& data,const QString& farPath);
-
- void getFile(const QString& fileName,const QString &srcPath);
-
- void getFile(QByteArray& data,const QString& srcPath);
-
- bool waitFinished(int msecs = 30000);
-
- bool getResult();
-
- bool createDir(const QString& path);
- signals:
-
- void signal_uploadState(bool flag);
-
- void signal_downloadState(bool flag);
-
- void signal_uploadProgress(qint64 bytesSent, qint64 bytesTotal);
-
- void signal_downloadProgress(qint64 bytesReceived, qint64 bytesTotal);
- #if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
-
- void signal_error(QNetworkReply::NetworkError);
- #endif
- private slots:
-
- void do_uploadFinished();
-
- void do_downloadFinished();
-
- void do_downloadFinishedToData();
-
- void do_uploadProgress(qint64 bytesSent, qint64 bytesTotal);
-
- void do_downloadProgress(qint64 bytesReceived, qint64 bytesTotal);
-
- void do_finished();
-
- void do_timeout();
- #if defined (QT_VERSION) && QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
- void do_ftpReplyError(QNetworkReply::NetworkError error);
- #endif
- private:
- bool m_isFinished = false;
- bool m_result = false;
- QTimer m_timer;
- QUrl m_url;
- QFile m_file;
- QByteArray *m_downloadData = nullptr;
- QNetworkAccessManager m_manager;
- QNetworkReply* m_reply = nullptr;
- };
- #endif
|