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//
41// W A R N I N G
42// -------------
43//
44// This file is not part of the Qt API. It exists for the convenience
45// of the Network Access API. This header file may change from
46// version to version without notice, or even be removed.
47//
48// We mean it.
49//
50
51#ifndef QFTP_P_H
52#define QFTP_P_H
53
54#include <QtNetwork/private/qtnetworkglobal_p.h>
55#include <QtCore/qstring.h>
56#include <private/qurlinfo_p.h>
57#include <QtCore/qobject.h>
58
59QT_REQUIRE_CONFIG(ftp);
60
61QT_BEGIN_NAMESPACE
62
63class QFtpPrivate;
64
65class Q_AUTOTEST_EXPORT QFtp : public QObject
66{
67 Q_OBJECT
68
69public:
70 explicit QFtp(QObject *parent = nullptr);
71 virtual ~QFtp();
72
73 enum State {
74 Unconnected,
75 HostLookup,
76 Connecting,
77 Connected,
78 LoggedIn,
79 Closing
80 };
81 enum Error {
82 NoError,
83 UnknownError,
84 HostNotFound,
85 ConnectionRefused,
86 NotConnected
87 };
88 enum Command {
89 None,
90 SetTransferMode,
91 SetProxy,
92 ConnectToHost,
93 Login,
94 Close,
95 List,
96 Cd,
97 Get,
98 Put,
99 Remove,
100 Mkdir,
101 Rmdir,
102 Rename,
103 RawCommand
104 };
105 enum TransferMode {
106 Active,
107 Passive
108 };
109 enum TransferType {
110 Binary,
111 Ascii
112 };
113
114 int setProxy(const QString &host, quint16 port);
115 int connectToHost(const QString &host, quint16 port=21);
116 int login(const QString &user = QString(), const QString &password = QString());
117 int close();
118 int setTransferMode(TransferMode mode);
119 int list(const QString &dir = QString());
120 int cd(const QString &dir);
121 int get(const QString &file, QIODevice *dev=nullptr, TransferType type = Binary);
122 int put(const QByteArray &data, const QString &file, TransferType type = Binary);
123 int put(QIODevice *dev, const QString &file, TransferType type = Binary);
124 int remove(const QString &file);
125 int mkdir(const QString &dir);
126 int rmdir(const QString &dir);
127 int rename(const QString &oldname, const QString &newname);
128
129 int rawCommand(const QString &command);
130
131 qint64 bytesAvailable() const;
132 qint64 read(char *data, qint64 maxlen);
133 QByteArray readAll();
134
135 int currentId() const;
136 QIODevice* currentDevice() const;
137 Command currentCommand() const;
138 bool hasPendingCommands() const;
139 void clearPendingCommands();
140
141 State state() const;
142
143 Error error() const;
144 QString errorString() const;
145
146public Q_SLOTS:
147 void abort();
148
149Q_SIGNALS:
150 void stateChanged(int);
151 void listInfo(const QUrlInfo&);
152 void readyRead();
153 void dataTransferProgress(qint64, qint64);
154 void rawCommandReply(int, const QString&);
155
156 void commandStarted(int);
157 void commandFinished(int, bool);
158 void done(bool);
159
160protected:
161 void clearError();
162
163private:
164 Q_DISABLE_COPY_MOVE(QFtp)
165 Q_DECLARE_PRIVATE(QFtp)
166
167 Q_PRIVATE_SLOT(d_func(), void _q_startNextCommand())
168 Q_PRIVATE_SLOT(d_func(), void _q_piFinished(const QString&))
169 Q_PRIVATE_SLOT(d_func(), void _q_piError(int, const QString&))
170 Q_PRIVATE_SLOT(d_func(), void _q_piConnectState(int))
171 Q_PRIVATE_SLOT(d_func(), void _q_piFtpReply(int, const QString&))
172};
173
174QT_END_NAMESPACE
175
176#endif // QFTP_P_H
177

source code of qtbase/src/network/access/qftp_p.h