FtpDataStream.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  * FtpDataStream.h
8  *
9  ****/
10 
11 #pragma once
12 
13 #include "FtpServerConnection.h"
14 #include "Network/TcpConnection.h"
15 
16 /*
17  RFC959:
18 
19  User-DTP listens on data port when required.
20 
21  Server is responsible for creating the data connection.
22 
23  The server MUST close the data connection under the following conditions:
24 
25  1. The server has completed sending data in a transfer mode
26  that requires a close to indicate EOF.
27 
28  2. The server receives an ABORT command from the user.
29 
30  3. The port specification is changed by a command from the user.
31 
32  4. The control connection is closed legally or otherwise.
33 
34  5. An irrecoverable error condition occurs.
35 
36  Otherwise the close is a server option, the exercise of which the
37  server must indicate to the user-process by either a 250 or 226
38  reply only.
39 */
41 {
42 public:
43  explicit FtpDataStream(FtpServerConnection& control) : TcpConnection(true), control(control)
44  {
45  }
46 
48  {
50  }
51 
52  err_t onConnected(err_t err) override
53  {
54  setTimeOut(300);
55  return TcpConnection::onConnected(err);
56  }
57 
59  {
60  close();
62  }
63 
64  void response(int code, String text = nullptr)
65  {
66  control.response(code, text);
67  }
68 
69  void onReadyToSendData(TcpConnectionEvent sourceEvent) override
70  {
71  if(completed) {
73  } else {
74  transferData(sourceEvent);
75  }
76  }
77 
78  virtual void transferData(TcpConnectionEvent sourceEvent)
79  {
80  }
81 
82 protected:
84  bool completed{false};
85 };
Definition: FtpDataStream.h:40
FtpDataStream(FtpServerConnection &control)
Definition: FtpDataStream.h:43
void dataStreamDestroyed(TcpConnection *connection)
void onReadyToSendData(TcpConnectionEvent sourceEvent) override
Definition: FtpDataStream.h:69
virtual void close()
Definition: TcpConnection.h:39
The String class.
Definition: WString.h:136
void response(int code, String text=nullptr)
Definition: FtpDataStream.h:64
virtual err_t onConnected(err_t err)
FtpServerConnection & control
Definition: FtpDataStream.h:83
void setTimeOut(uint16_t waitTimeOut)
TcpConnectionEvent
Definition: TcpConnection.h:25
virtual void response(int code, String text=nullptr, char sep=' ')
void dataTransferFinished(TcpConnection *connection)
void finishTransfer()
Definition: FtpDataStream.h:58
bool completed
Definition: FtpDataStream.h:84
Definition: FtpServerConnection.h:27
virtual void transferData(TcpConnectionEvent sourceEvent)
Definition: FtpDataStream.h:78
err_t onConnected(err_t err) override
Definition: FtpDataStream.h:52
~FtpDataStream()
Definition: FtpDataStream.h:47