summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Plasa <dplasa@gmail.com>2020-05-29 14:17:09 +0200
committerDaniel Plasa <dplasa@gmail.com>2020-05-29 14:17:09 +0200
commite1d603771be3f32205cf854db7cb9d86d441852a (patch)
tree7682411b38c47e997359b908ad867308ba180578
parentremove duplicates (diff)
downloadFTPCLientServer-e1d603771be3f32205cf854db7cb9d86d441852a.tar
FTPCLientServer-e1d603771be3f32205cf854db7cb9d86d441852a.tar.gz
FTPCLientServer-e1d603771be3f32205cf854db7cb9d86d441852a.tar.bz2
FTPCLientServer-e1d603771be3f32205cf854db7cb9d86d441852a.tar.lz
FTPCLientServer-e1d603771be3f32205cf854db7cb9d86d441852a.tar.xz
FTPCLientServer-e1d603771be3f32205cf854db7cb9d86d441852a.tar.zst
FTPCLientServer-e1d603771be3f32205cf854db7cb9d86d441852a.zip
-rw-r--r--FTPClient.cpp16
-rw-r--r--FTPClient.h14
2 files changed, 19 insertions, 11 deletions
diff --git a/FTPClient.cpp b/FTPClient.cpp
index c6cccc1..e32af21 100644
--- a/FTPClient.cpp
+++ b/FTPClient.cpp
@@ -33,7 +33,7 @@ const FTPClient::Status &FTPClient::transfer(const String &localFileName, const
if (!file)
{
_serverStatus.result = ERROR;
- _serverStatus.code = 65530;
+ _serverStatus.code = errorLocalFile;
_serverStatus.desc = F("Local file error");
}
else
@@ -52,7 +52,7 @@ const FTPClient::Status &FTPClient::transfer(const String &localFileName, const
else
{
// return error code with status "in PROGRESS"
- _serverStatus.code = 65529;
+ _serverStatus.code = errorAlreadyInProgress;
}
return _serverStatus;
}
@@ -67,7 +67,7 @@ void FTPClient::handleFTP()
if (_server == nullptr)
{
_serverStatus.result = TransferResult::ERROR;
- _serverStatus.code = 65535;
+ _serverStatus.code = errorUninitialized;
_serverStatus.desc = F("begin() not called");
}
else if (ftpState > cIdle)
@@ -76,7 +76,7 @@ void FTPClient::handleFTP()
}
else if (cConnect == ftpState)
{
- _serverStatus.code = 65534;
+ _serverStatus.code = errorConnectionFailed;
_serverStatus.desc = F("No connection to FTP server");
if (controlConnect())
{
@@ -138,7 +138,7 @@ void FTPClient::handleFTP()
}
if (!parseOK)
{
- _serverStatus.code = 65533;
+ _serverStatus.code = errorServerResponse;
_serverStatus.desc = F("FTP server response not understood.");
}
}
@@ -148,7 +148,7 @@ void FTPClient::handleFTP()
// open data connection
if (dataConnect() < 0)
{
- _serverStatus.code = 65532;
+ _serverStatus.code = errorDataConnectionFailed;
_serverStatus.desc = F("No data connection to FTP server");
ftpState = cError;
}
@@ -231,7 +231,7 @@ bool FTPClient::waitFor(const uint16_t respCode, const __FlashStringHelper *erro
if ((int32_t)(millis() - waitUntil) >= 0)
{
FTP_DEBUG_MSG("Waiting for code %u - timeout!", respCode);
- _serverStatus.code = 65535;
+ _serverStatus.code = errorTimeout;
if (errorString)
{
_serverStatus.desc = errorString;
@@ -258,7 +258,7 @@ bool FTPClient::waitFor(const uint16_t respCode, const __FlashStringHelper *erro
continue;
// line complete, evaluate code
- _serverStatus.code = strtol(_serverStatus.desc.c_str(), NULL, 0);
+ _serverStatus.code = atoi(_serverStatus.desc.c_str());
if (respCode != _serverStatus.code)
{
ftpState = cError;
diff --git a/FTPClient.h b/FTPClient.h
index d252add..1d3d6b4 100644
--- a/FTPClient.h
+++ b/FTPClient.h
@@ -43,10 +43,18 @@ public:
ERROR,
} TransferResult;
+ static constexpr int16_t errorLocalFile = -1;
+ static constexpr int16_t errorAlreadyInProgress = -2;
+ static constexpr int16_t errorConnectionFailed = -3;
+ static constexpr int16_t errorServerResponse = -4;
+ static constexpr int16_t errorDataConnectionFailed = -5;
+ static constexpr int16_t errorUninitialized = -6;
+ static constexpr int16_t errorTimeout = -7;
+
typedef struct
{
TransferResult result;
- uint16_t code;
+ int16_t code;
String desc;
} Status;
@@ -75,7 +83,7 @@ public:
void handleFTP();
protected:
- typedef enum
+ typedef enum
{
cConnect = 0,
cGreet,
@@ -98,7 +106,7 @@ protected:
String _remoteFileName;
TransferType _direction;
- int8_t controlConnect(); // connects to ServerInfo, returns -1: no connection possible, +1: connection established
+ int8_t controlConnect(); // connects to ServerInfo, returns -1: no connection possible, +1: connection established
bool waitFor(const uint16_t respCode, const __FlashStringHelper *errorString = nullptr, uint16_t timeOut = 10000);
};