12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- #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;
- QFile m_fileUpload;
- QByteArray *m_downloadData = nullptr;
- QNetworkAccessManager m_manager;
- QNetworkReply* m_reply = nullptr;
- };
- #endif
|