qftp.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. /****************************************************************************
  2. **
  3. ** Copyright (C) 2016 The Qt Company Ltd.
  4. ** Contact: https://www.qt.io/licensing/
  5. **
  6. ** This file is part of the QtNetwork module of the Qt Toolkit.
  7. **
  8. ** $QT_BEGIN_LICENSE:LGPL$
  9. ** Commercial License Usage
  10. ** Licensees holding valid commercial Qt licenses may use this file in
  11. ** accordance with the commercial license agreement provided with the
  12. ** Software or, alternatively, in accordance with the terms contained in
  13. ** a written agreement between you and The Qt Company. For licensing terms
  14. ** and conditions see https://www.qt.io/terms-conditions. For further
  15. ** information use the contact form at https://www.qt.io/contact-us.
  16. **
  17. ** GNU Lesser General Public License Usage
  18. ** Alternatively, this file may be used under the terms of the GNU Lesser
  19. ** General Public License version 3 as published by the Free Software
  20. ** Foundation and appearing in the file LICENSE.LGPL3 included in the
  21. ** packaging of this file. Please review the following information to
  22. ** ensure the GNU Lesser General Public License version 3 requirements
  23. ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
  24. **
  25. ** GNU General Public License Usage
  26. ** Alternatively, this file may be used under the terms of the GNU
  27. ** General Public License version 2.0 or (at your option) the GNU General
  28. ** Public license version 3 or any later version approved by the KDE Free
  29. ** Qt Foundation. The licenses are as published by the Free Software
  30. ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
  31. ** included in the packaging of this file. Please review the following
  32. ** information to ensure the GNU General Public License requirements will
  33. ** be met: https://www.gnu.org/licenses/gpl-2.0.html and
  34. ** https://www.gnu.org/licenses/gpl-3.0.html.
  35. **
  36. ** $QT_END_LICENSE$
  37. **
  38. ****************************************************************************/
  39. //
  40. // W A R N I N G
  41. // -------------
  42. //
  43. // This file is not part of the Qt API. It exists for the convenience
  44. // of the Network Access API. This header file may change from
  45. // version to version without notice, or even be removed.
  46. //
  47. // We mean it.
  48. //
  49. #ifndef QFTP_P_H
  50. #define QFTP_P_H
  51. #include <QtCore/qstring.h>
  52. #include <QtCore/qobject.h>
  53. #include <QFile>
  54. #include "qurlinfo.h"
  55. //QT_REQUIRE_CONFIG(ftp);
  56. QT_BEGIN_NAMESPACE
  57. class QFtpPrivate;
  58. class QFtp : public QObject
  59. {
  60. Q_OBJECT
  61. public:
  62. explicit QFtp(QObject *parent = nullptr);
  63. virtual ~QFtp();
  64. enum State {
  65. Unconnected,
  66. HostLookup,
  67. Connecting,
  68. Connected,
  69. LoggedIn,
  70. Closing
  71. };
  72. enum Error {
  73. NoError,
  74. UnknownError,
  75. HostNotFound,
  76. ConnectionRefused,
  77. NotConnected
  78. };
  79. enum Command {
  80. None,
  81. SetTransferMode,
  82. SetProxy,
  83. ConnectToHost,
  84. Login,
  85. Close,
  86. List,
  87. Cd,
  88. Get,
  89. Put,
  90. Remove,
  91. Mkdir,
  92. Rmdir,
  93. Rename,
  94. RawCommand
  95. };
  96. enum TransferMode {
  97. Active,
  98. Passive
  99. };
  100. enum TransferType {
  101. Binary,
  102. Ascii
  103. };
  104. int setProxy(const QString &host, quint16 port);
  105. int connectToHost(const QString &host, quint16 port=21);
  106. int login(const QString &user = QString(), const QString &password = QString());
  107. int close();
  108. int setTransferMode(TransferMode mode);
  109. int list(const QString &dir = QString());
  110. int cd(const QString &dir);
  111. int get(const QString &file, QIODevice *dev=nullptr, TransferType type = Binary);
  112. int put(const QByteArray &data, const QString &file, TransferType type = Binary);
  113. int put(QIODevice *dev, const QString &file, TransferType type = Binary);
  114. int remove(const QString &file);
  115. int mkdir(const QString &dir);
  116. int rmdir(const QString &dir);
  117. int rename(const QString &oldname, const QString &newname);
  118. int rawCommand(const QString &command);
  119. qint64 bytesAvailable() const;
  120. qint64 read(char *data, qint64 maxlen);
  121. QByteArray readAll();
  122. int currentId() const;
  123. QIODevice* currentDevice() const;
  124. Command currentCommand() const;
  125. bool hasPendingCommands() const;
  126. void clearPendingCommands();
  127. State state() const;
  128. Error error() const;
  129. QString errorString() const;
  130. public Q_SLOTS:
  131. void abort();
  132. Q_SIGNALS:
  133. void stateChanged(int);
  134. void listInfo(const QUrlInfo&);
  135. void readyRead();
  136. void dataTransferProgress(qint64, qint64);
  137. void rawCommandReply(int, const QString&);
  138. void commandStarted(int);
  139. void commandFinished(int, bool);
  140. void done(bool);
  141. protected:
  142. void clearError();
  143. private:
  144. // Q_DISABLE_COPY_MOVE(QFtp)
  145. Q_DISABLE_COPY(QFtp)
  146. QScopedPointer<QFtpPrivate> d;
  147. // Q_DECLARE_PRIVATE(QFtp)
  148. Q_PRIVATE_SLOT(d, void _q_startNextCommand())
  149. Q_PRIVATE_SLOT(d, void _q_piFinished(const QString&))
  150. Q_PRIVATE_SLOT(d, void _q_piError(int, const QString&))
  151. Q_PRIVATE_SLOT(d, void _q_piConnectState(int))
  152. Q_PRIVATE_SLOT(d, void _q_piFtpReply(int, const QString&))
  153. };
  154. QT_END_NAMESPACE
  155. #endif // QFTP_P_H