1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- #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();
- #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
|