summaryrefslogtreecommitdiffstats
path: root/examples/scxml/ftpclient/ftpcontrolchannel.h
blob: 46dc2e877f83e1cb0a496c9977d340d2afbd3784 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause

#ifndef FTPCONTROLCHANNEL_H
#define FTPCONTROLCHANNEL_H

#include <QHostAddress>
#include <QObject>
#include <QTcpSocket>

class FtpControlChannel : public QObject
{
    Q_OBJECT
public:
    explicit FtpControlChannel(QObject *parent = nullptr);

    // Connect to an FTP server
    void connectToServer(const QString &server);

    // Send a command to the server
    void command(const QByteArray &command, const QByteArray &params);

public slots:
    void error(QAbstractSocket::SocketError);

signals:

    // Connection established. Local address and port are known.
    void opened(const QHostAddress &localAddress, int localPort);

    // Connection closed
    void closed();

    // Informational message
    void info(const QByteArray &info);

    // Reply to a previously sent command
    void reply(int code, const QByteArray &parameters);

    // Something is wrong
    void invalidReply(const QByteArray &reply);

private:
    void onReadyRead();

    QTcpSocket m_socket;
    QByteArray m_buffer;
};

#endif // FTPCONTROLCHANNEL_H