FtpServerConnection.h
Go to the documentation of this file.
1 /****
2  * Sming Framework Project - Open Source framework for high efficiency native ESP8266 development.
3  * Created 2015 by Skurydin Alexey
4  * http://github.com/SmingHub/Sming
5  * All files of the Sming Core are provided under the LGPL v3 license.
6  *
7  * FtpServerConnection.h
8  *
9  ****/
10 
11 #pragma once
12 
13 #include "Network/TcpConnection.h"
14 #include "IpAddress.h"
15 #include "WString.h"
16 
23 class FtpServer;
24 
26 {
27  friend class FtpDataStream;
28  friend class FtpServer;
29 
30 public:
31  static constexpr size_t MAX_FTP_CMD{255};
32 
33  FtpServerConnection(FtpServer& parentServer, tcp_pcb* clientTcp)
34  : TcpConnection(clientTcp, true), server(parentServer)
35  {
36  }
37 
38  err_t onReceive(pbuf* buf) override;
39  err_t onSent(uint16_t len) override;
40  void onReadyToSendData(TcpConnectionEvent sourceEvent) override;
41 
42  void dataTransferFinished(TcpConnection* connection);
43 
44 protected:
45  virtual void onCommand(String cmd, String data);
46  virtual void response(int code, String text = "");
47 
48  void cmdPort(const String& data);
49  void createDataConnection(TcpConnection* connection);
50 
52  {
53  return canTransfer;
54  }
55 
56 private:
57  enum class State {
58  Ready,
59  Authorization,
60  Active,
61  };
62 
63  FtpServer& server;
64  State state{State::Ready};
65  String userName;
66  String renameFrom;
67 
68  IpAddress ip;
69  int port{0};
70  TcpConnection* dataConnection{nullptr};
71  bool canTransfer{true};
72 };
73 
74 typedef FtpServerConnection FTPServerConnection SMING_DEPRECATED; // @deprecated Use `FtpServerConnection` instead
75 
A class to make it easier to handle and pass around IP addresses.
Definition: IpAddress.h:43
void onReadyToSendData(TcpConnectionEvent sourceEvent) override
Definition: FtpDataStream.h:16
err_t onReceive(pbuf *buf) override
virtual void onCommand(String cmd, String data)
void cmdPort(const String &data)
Definition: TcpConnection.h:39
The String class.
Definition: WString.h:136
virtual void response(int code, String text="")
TcpConnectionEvent
Definition: TcpConnection.h:25
void dataTransferFinished(TcpConnection *connection)
FtpServerConnection(FtpServer &parentServer, tcp_pcb *clientTcp)
Definition: FtpServerConnection.h:33
#define SMING_DEPRECATED
Definition: sming_attr.h:30
void createDataConnection(TcpConnection *connection)
Definition: FtpServerConnection.h:25
static constexpr size_t MAX_FTP_CMD
Definition: FtpServerConnection.h:31
err_t onSent(uint16_t len) override
bool isCanTransfer()
Definition: FtpServerConnection.h:51
Definition: FtpServer.h:23