mirror of
https://github.com/HASwitchPlate/openHASP.git
synced 2025-07-28 05:36:37 +00:00
Workaround for PASV with FTP started early
This commit is contained in:
parent
5052186e4a
commit
152d366822
@ -439,7 +439,7 @@ bool FtpServer::processCommand()
|
||||
} else {
|
||||
dataIp = NET_CLASS.localIP(); // same subnet without manual IP set
|
||||
}
|
||||
} else{
|
||||
} else {
|
||||
dataIp = NET_CLASS.localIP(); // other subnet, no NAT
|
||||
}
|
||||
dataPort = pasvPort;
|
||||
@ -470,12 +470,11 @@ bool FtpServer::processCommand()
|
||||
client.print((dataPort & 255));
|
||||
client.println(F(")"));
|
||||
dataConn = FTP_Pasive;
|
||||
}
|
||||
//
|
||||
// PORT - Data Port
|
||||
//
|
||||
else if(CommandIs("PORT"))
|
||||
{
|
||||
}
|
||||
//
|
||||
// PORT - Data Port
|
||||
//
|
||||
else if(CommandIs("PORT")) {
|
||||
data.stop();
|
||||
// get IP of data client
|
||||
dataIp[0] = atoi(parameter);
|
||||
@ -505,12 +504,11 @@ else if(CommandIs("PORT"))
|
||||
client.println(F("200 PORT command successful"));
|
||||
dataConn = FTP_Active;
|
||||
}
|
||||
}
|
||||
//
|
||||
// STRU - File Structure
|
||||
//
|
||||
else if(CommandIs("STRU"))
|
||||
{
|
||||
}
|
||||
//
|
||||
// STRU - File Structure
|
||||
//
|
||||
else if(CommandIs("STRU")) {
|
||||
if(ParameterIs("F")) {
|
||||
client.println(F("200 F Ok"));
|
||||
// else if( ParameterIs( "R" ))
|
||||
@ -518,12 +516,11 @@ else if(CommandIs("STRU"))
|
||||
} else {
|
||||
client.println(F("504 Only F(ile) is suported"));
|
||||
}
|
||||
}
|
||||
//
|
||||
// TYPE - Data Type
|
||||
//
|
||||
else if(CommandIs("TYPE"))
|
||||
{
|
||||
}
|
||||
//
|
||||
// TYPE - Data Type
|
||||
//
|
||||
else if(CommandIs("TYPE")) {
|
||||
if(ParameterIs("A")) {
|
||||
client.println(F("200 TYPE is now ASCII"));
|
||||
} else if(ParameterIs("I")) {
|
||||
@ -531,27 +528,25 @@ else if(CommandIs("TYPE"))
|
||||
} else {
|
||||
client.println(F("504 Unknow TYPE"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
///////////////////////////////////////
|
||||
// //
|
||||
// FTP SERVICE COMMANDS //
|
||||
// //
|
||||
///////////////////////////////////////
|
||||
///////////////////////////////////////
|
||||
// //
|
||||
// FTP SERVICE COMMANDS //
|
||||
// //
|
||||
///////////////////////////////////////
|
||||
|
||||
//
|
||||
// ABOR - Abort
|
||||
//
|
||||
else if(CommandIs("ABOR"))
|
||||
{
|
||||
//
|
||||
// ABOR - Abort
|
||||
//
|
||||
else if(CommandIs("ABOR")) {
|
||||
abortTransfer();
|
||||
client.println(F("226 Data connection closed"));
|
||||
}
|
||||
//
|
||||
// DELE - Delete a File
|
||||
//
|
||||
else if(CommandIs("DELE"))
|
||||
{
|
||||
}
|
||||
//
|
||||
// DELE - Delete a File
|
||||
//
|
||||
else if(CommandIs("DELE")) {
|
||||
char path[FTP_CWD_SIZE];
|
||||
if(haveParameter() && makeExistsPath(path)) {
|
||||
if(remove(path)) {
|
||||
@ -566,14 +561,13 @@ else if(CommandIs("DELE"))
|
||||
client.println(parameter);
|
||||
}
|
||||
}
|
||||
}
|
||||
//
|
||||
// LIST - List
|
||||
// NLST - Name List
|
||||
// MLSD - Listing for Machine Processing (see RFC 3659)
|
||||
//
|
||||
else if(CommandIs("LIST") || CommandIs("NLST") || CommandIs("MLSD"))
|
||||
{
|
||||
}
|
||||
//
|
||||
// LIST - List
|
||||
// NLST - Name List
|
||||
// MLSD - Listing for Machine Processing (see RFC 3659)
|
||||
//
|
||||
else if(CommandIs("LIST") || CommandIs("NLST") || CommandIs("MLSD")) {
|
||||
DEBUG_PRINT("List of file!!");
|
||||
|
||||
if(dataConnect()) {
|
||||
@ -592,12 +586,11 @@ else if(CommandIs("LIST") || CommandIs("NLST") || CommandIs("MLSD"))
|
||||
data.stop();
|
||||
}
|
||||
}
|
||||
}
|
||||
//
|
||||
// MLST - Listing for Machine Processing (see RFC 3659)
|
||||
//
|
||||
else if(CommandIs("MLST"))
|
||||
{
|
||||
}
|
||||
//
|
||||
// MLST - Listing for Machine Processing (see RFC 3659)
|
||||
//
|
||||
else if(CommandIs("MLST")) {
|
||||
char path[FTP_CWD_SIZE];
|
||||
uint16_t dat, tim;
|
||||
char dtStr[15];
|
||||
@ -625,19 +618,17 @@ else if(CommandIs("MLST"))
|
||||
client.println(F("250 End."));
|
||||
}
|
||||
}
|
||||
}
|
||||
//
|
||||
// NOOP
|
||||
//
|
||||
else if(CommandIs("NOOP"))
|
||||
{
|
||||
}
|
||||
//
|
||||
// NOOP
|
||||
//
|
||||
else if(CommandIs("NOOP")) {
|
||||
client.println(F("200 Zzz..."));
|
||||
}
|
||||
//
|
||||
// RETR - Retrieve
|
||||
//
|
||||
else if(CommandIs("RETR"))
|
||||
{
|
||||
}
|
||||
//
|
||||
// RETR - Retrieve
|
||||
//
|
||||
else if(CommandIs("RETR")) {
|
||||
char path[FTP_CWD_SIZE];
|
||||
if(haveParameter() && makeExistsPath(path)) {
|
||||
if(!openFile(path, FTP_FILE_READ)) {
|
||||
@ -663,13 +654,12 @@ else if(CommandIs("RETR"))
|
||||
transferStage = FTP_Retrieve;
|
||||
}
|
||||
}
|
||||
}
|
||||
//
|
||||
// STOR - Store
|
||||
// APPE - Append
|
||||
//
|
||||
else if(CommandIs("STOR") || CommandIs("APPE"))
|
||||
{
|
||||
}
|
||||
//
|
||||
// STOR - Store
|
||||
// APPE - Append
|
||||
//
|
||||
else if(CommandIs("STOR") || CommandIs("APPE")) {
|
||||
char path[FTP_CWD_SIZE];
|
||||
if(haveParameter() && makePath(path)) {
|
||||
bool open;
|
||||
@ -706,12 +696,11 @@ else if(CommandIs("STOR") || CommandIs("APPE"))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
//
|
||||
// MKD - Make Directory
|
||||
//
|
||||
else if(CommandIs("MKD"))
|
||||
{
|
||||
}
|
||||
//
|
||||
// MKD - Make Directory
|
||||
//
|
||||
else if(CommandIs("MKD")) {
|
||||
char path[FTP_CWD_SIZE];
|
||||
if(haveParameter() && makePath(path)) {
|
||||
if(exists(path)) {
|
||||
@ -738,12 +727,11 @@ else if(CommandIs("MKD"))
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
//
|
||||
// RMD - Remove a Directory
|
||||
//
|
||||
else if(CommandIs("RMD"))
|
||||
{
|
||||
}
|
||||
//
|
||||
// RMD - Remove a Directory
|
||||
//
|
||||
else if(CommandIs("RMD")) {
|
||||
char path[FTP_CWD_SIZE];
|
||||
if(haveParameter() && makeExistsPath(path)) {
|
||||
if(removeDir(path)) {
|
||||
@ -759,12 +747,11 @@ else if(CommandIs("RMD"))
|
||||
client.println(F("\". Directory not empty?"));
|
||||
}
|
||||
}
|
||||
}
|
||||
//
|
||||
// RNFR - Rename From
|
||||
//
|
||||
else if(CommandIs("RNFR"))
|
||||
{
|
||||
}
|
||||
//
|
||||
// RNFR - Rename From
|
||||
//
|
||||
else if(CommandIs("RNFR")) {
|
||||
rnfrName[0] = 0;
|
||||
if(haveParameter() && makeExistsPath(rnfrName)) {
|
||||
DEBUG_PRINT(F(" Ready for renaming "));
|
||||
@ -773,12 +760,11 @@ else if(CommandIs("RNFR"))
|
||||
client.println(F("350 RNFR accepted - file exists, ready for destination"));
|
||||
rnfrCmd = true;
|
||||
}
|
||||
}
|
||||
//
|
||||
// RNTO - Rename To
|
||||
//
|
||||
else if(CommandIs("RNTO"))
|
||||
{
|
||||
}
|
||||
//
|
||||
// RNTO - Rename To
|
||||
//
|
||||
else if(CommandIs("RNTO")) {
|
||||
char path[FTP_CWD_SIZE];
|
||||
char dirp[FTP_FIL_SIZE];
|
||||
if(strlen(rnfrName) == 0 || !rnfrCmd) {
|
||||
@ -816,26 +802,25 @@ else if(CommandIs("RNTO"))
|
||||
}
|
||||
}
|
||||
rnfrCmd = false;
|
||||
}
|
||||
/*
|
||||
//
|
||||
// SYST - System
|
||||
//
|
||||
else if( CommandIs( "SYST" ))
|
||||
}
|
||||
/*
|
||||
//
|
||||
// SYST - System
|
||||
//
|
||||
else if( CommandIs( "SYST" ))
|
||||
FtpOutCli << F("215 MSDOS") << endl;
|
||||
*/
|
||||
*/
|
||||
|
||||
///////////////////////////////////////
|
||||
// //
|
||||
// EXTENSIONS COMMANDS (RFC 3659) //
|
||||
// //
|
||||
///////////////////////////////////////
|
||||
///////////////////////////////////////
|
||||
// //
|
||||
// EXTENSIONS COMMANDS (RFC 3659) //
|
||||
// //
|
||||
///////////////////////////////////////
|
||||
|
||||
//
|
||||
// MDTM && MFMT - File Modification Time (see RFC 3659)
|
||||
//
|
||||
else if(CommandIs("MDTM") || CommandIs("MFMT"))
|
||||
{
|
||||
//
|
||||
// MDTM && MFMT - File Modification Time (see RFC 3659)
|
||||
//
|
||||
else if(CommandIs("MDTM") || CommandIs("MFMT")) {
|
||||
if(haveParameter()) {
|
||||
char path[FTP_CWD_SIZE];
|
||||
char* fname = parameter;
|
||||
@ -871,12 +856,11 @@ else if(CommandIs("MDTM") || CommandIs("MFMT"))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
//
|
||||
// SIZE - Size of the file
|
||||
//
|
||||
else if(CommandIs("SIZE"))
|
||||
{
|
||||
}
|
||||
//
|
||||
// SIZE - Size of the file
|
||||
//
|
||||
else if(CommandIs("SIZE")) {
|
||||
char path[FTP_CWD_SIZE];
|
||||
if(haveParameter() && makeExistsPath(path)) {
|
||||
if(!openFile(path, FTP_FILE_READ)) {
|
||||
@ -888,12 +872,11 @@ else if(CommandIs("SIZE"))
|
||||
file.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
//
|
||||
// SITE - System command
|
||||
//
|
||||
else if(CommandIs("SITE"))
|
||||
{
|
||||
}
|
||||
//
|
||||
// SITE - System command
|
||||
//
|
||||
else if(CommandIs("SITE")) {
|
||||
if(ParameterIs("FREE")) {
|
||||
uint32_t capa = capacity();
|
||||
if((capa >> 10) < 1000) { // less than 1 Giga
|
||||
@ -913,12 +896,13 @@ else if(CommandIs("SITE"))
|
||||
client.print(F("500 Unknow SITE command "));
|
||||
client.println(parameter);
|
||||
}
|
||||
}
|
||||
//
|
||||
// Unrecognized commands ...
|
||||
//
|
||||
else client.println(F("500 Unknow command"));
|
||||
return true;
|
||||
}
|
||||
//
|
||||
// Unrecognized commands ...
|
||||
//
|
||||
else
|
||||
client.println(F("500 Unknow command"));
|
||||
return true;
|
||||
}
|
||||
|
||||
int FtpServer::dataConnect(bool out150)
|
||||
|
Loading…
x
Reference in New Issue
Block a user