-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathFileTransferManager.cpp
More file actions
136 lines (116 loc) · 4.27 KB
/
FileTransferManager.cpp
File metadata and controls
136 lines (116 loc) · 4.27 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
/**************************************************************************/
/*!
@file FileTransferManager.cpp
@author Nitin Nair (EmotiBit)
@mainpage File transfer manager for EmotiBit
@section intro_sec Introduction
This is a library to file transfers on EmotiBit.
EmotiBit invests time and resources providing this open source code,
please support EmotiBit and open-source hardware by purchasing
products from EmotiBit!
@section author Author
Written by Nitin Nair for EmotiBit.
@section HISTORY
v1.0 - First release
@section license License
BSD license, all text here must be included in any redistribution
*/
/**************************************************************************/
#include "FileTransferManager.h"
bool FileTransferManager::begin()
{
Serial.println("Setting Mode to File Transfer");
setMode(FileTransferManager::Mode::FILE_TRANSFER);
if(getProtocol() == Protocol::FTP)
{
if(WiFi.status() != WL_CONNECTED)
{
Serial.println("FTP server needs WiFi connection. Please connect to a WiFi network before starting FTP server");
Serial.println("Please restart MCU, connect to WiFi and then start FTP server");
return false;
}
else
{
// in FTP
// create FTP server
Serial.print("On network: "); Serial.println(WiFi.SSID());
Serial.print("FTP server started at IP: "); Serial.println(WiFi.localIP());
Serial.println("Use a FTP client (Example FileZilla) to access EmotiBit file system.");
Serial.println("------- FileZilla Isstructions -------");
Serial.println("File > Site Manager > New site. Enter a name for the site and Set the parameters as shown below: ");
Serial.println("- Protocol = FTP");
Serial.println("- Host = [enter the IP address printed above]");
Serial.println("- Encription = Select Use plain FTP (insecure)");
Serial.println("- Logon Type = Ask for password");
Serial.println("- Enter the login username and password (when prompted), as set in the EmotiBit firmware (default username=ftp, password=ftp)");
Serial.println("- Under \"Transfer settings\" tab > Check \"Limit number of simultaneous connections\". Select \"Maximun number of connections:\" equal to 1");
Serial.println("Now you can connect to your EmotiBit(server)!");
// start FTP server
ftpServer.begin(_ftpCreds.username.c_str(), _ftpCreds.password.c_str());
return true;
}
}
else
{
// implement other protocol
return false;
}
return false;
}
void FileTransferManager::setFtpAuth(String username, String password)
{
_ftpCreds.username = username;
_ftpCreds.password = password;
}
bool FileTransferManager::setProtocol(Protocol protocol)
{
_protocol = protocol;
// ToDo: Handle all conditions that may result in a return false
return true;
}
FileTransferManager::Protocol FileTransferManager::getProtocol()
{
return _protocol;
}
bool FileTransferManager::setMode(Mode mode)
{
_mode = mode;
return true;
}
FileTransferManager::Mode FileTransferManager::getMode()
{
return _mode;
}
void FileTransferManager::handleTransfer()
{
if(getMode() == Mode::FILE_TRANSFER)
{
if(getProtocol() == Protocol::FTP)
{
if(WiFi.status() != WL_CONNECTED)
{
Serial.println("FTP server needs WiFi connection. Please connect to a WiFi network before starting FTP server");
Serial.println("Please restart MCU, connect to WiFi and then start FTP server");
while(1);
}
else
{
// handleFTP requests. To get back to normal mode, press reset
ftpServer.handleFTP();
return;
}
}
else
{
Serial.println("Protocol not Implemented. Please check FileTransferManager::handleTransfer for more details");
setMode(Mode::NORMAL);
Serial.println("Reset MCU to start again");
while(1);
}
}
else
{
// not in file transfer mode. Do nothing.
return;
}
}