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 #define MAX_FTP_CMD 255
24 
25 class FtpServer;
26 
28 
30 {
31  friend class FtpDataStream;
32  friend class FtpServer;
33 
34 public:
35  FtpServerConnection(FtpServer* parentServer, tcp_pcb* clientTcp)
36  : TcpConnection(clientTcp, true), server(parentServer)
37  {
38  }
39 
40  err_t onReceive(pbuf* buf) override;
41  err_t onSent(uint16_t len) override;
42  void onReadyToSendData(TcpConnectionEvent sourceEvent) override;
43 
44  void dataTransferFinished(TcpConnection* connection);
45 
46 protected:
47  virtual void onCommand(String cmd, String data);
48  virtual void response(int code, String text = "");
49 
50  int getSplitterPos(const String& data, char splitter, uint8_t number);
51  String makeFileName(String name, bool shortIt);
52 
53  void cmdPort(const String& data);
54  void createDataConnection(TcpConnection* connection);
55 
57  {
58  return canTransfer;
59  }
60 
61 private:
62  FtpServer* server = nullptr;
64  String userName;
65  String renameFrom;
66 
67  IpAddress ip;
68  int port = 0;
69  TcpConnection* dataConnection = nullptr;
70  bool canTransfer = true;
71 };
72 
73 typedef FtpServerConnection FTPServerConnection SMING_DEPRECATED; // @deprecated Use `FtpServerConnection` instead
74 
A class to make it easier to handle and pass around IP addresses.
Definition: IpAddress.h:43
void onReadyToSendData(TcpConnectionEvent sourceEvent) override
String makeFileName(String name, bool shortIt)
Definition: FtpDataStream.h:16
err_t onReceive(pbuf *buf) override
Definition: FtpServerConnection.h:27
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)
#define SMING_DEPRECATED
Definition: sming_attr.h:30
Definition: FtpServerConnection.h:27
void createDataConnection(TcpConnection *connection)
Definition: FtpServerConnection.h:29
int getSplitterPos(const String &data, char splitter, uint8_t number)
err_t onSent(uint16_t len) override
FtpConnectionState
Definition: FtpServerConnection.h:27
FtpServerConnection(FtpServer *parentServer, tcp_pcb *clientTcp)
Definition: FtpServerConnection.h:35
bool isCanTransfer()
Definition: FtpServerConnection.h:56
Definition: FtpServerConnection.h:27
Definition: FtpServer.h:25