summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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);
};