mirror of
https://github.com/pocoproject/poco.git
synced 2025-10-26 18:42:41 +01:00
Add FTPS (FTP over explicit SSL) implementation (#1866)
* FTPSClientSession Add class to support FTPS (explicit FTP over SSL). Testcase done but just TestSuite_x64_vs140.vcxproj modified * FTPS project file Added FTPS files to v140 project * FTPS makefile Added FTPS file to makefile * testsuit compile Fix compile of testsuite * comment misspelled checked misspelled comment, and re-add WebSocket testsuite * remove warning reorder constructor inizializzations in order to remove gcc -Wreorder warning * testsuite compile Correct Makefile in testsuite * Makefile testsuite add DialogServer to testsuite makefile * test build fix build of testsuite * add FTPSStreamFactory * vs140 32bit * build and test for vs150
This commit is contained in:
committed by
Aleksandar Fabijanic
parent
96ca6e865d
commit
dd573b98d8
@@ -101,14 +101,14 @@ public:
|
||||
bool getPassive() const;
|
||||
/// Returns true iff passive mode is enabled for this connection.
|
||||
|
||||
void open(const std::string& host,
|
||||
virtual void open(const std::string& host,
|
||||
Poco::UInt16 port,
|
||||
const std::string& username = "",
|
||||
const std::string& password = "");
|
||||
/// Opens the FTP connection to the given host and port.
|
||||
/// If username is supplied, login is attempted.
|
||||
|
||||
void login(const std::string& username, const std::string& password);
|
||||
virtual void login(const std::string& username, const std::string& password);
|
||||
/// Authenticates the user against the FTP server. Must be
|
||||
/// called before any other commands (except QUIT) can be sent.
|
||||
///
|
||||
@@ -304,7 +304,13 @@ public:
|
||||
bool isLoggedIn() const;
|
||||
/// Returns true if the session is logged in.
|
||||
|
||||
bool isSecure() const;
|
||||
/// Returns true if the session is FTPS.
|
||||
|
||||
protected:
|
||||
virtual void receiveServerReadyReply();
|
||||
/// Function that read server welcome message after connetion
|
||||
|
||||
enum StatusClass
|
||||
{
|
||||
FTP_POSITIVE_PRELIMINARY = 1,
|
||||
@@ -324,7 +330,7 @@ protected:
|
||||
static bool isTransientNegative(int status);
|
||||
static bool isPermanentNegative(int status);
|
||||
std::string extractPath(const std::string& response);
|
||||
StreamSocket establishDataConnection(const std::string& command, const std::string& arg);
|
||||
virtual StreamSocket establishDataConnection(const std::string& command, const std::string& arg);
|
||||
StreamSocket activeDataConnection(const std::string& command, const std::string& arg);
|
||||
StreamSocket passiveDataConnection(const std::string& command, const std::string& arg);
|
||||
void sendPortCommand(const SocketAddress& addr);
|
||||
@@ -336,21 +342,21 @@ protected:
|
||||
void parseAddress(const std::string& str, SocketAddress& addr);
|
||||
void parseExtAddress(const std::string& str, SocketAddress& addr);
|
||||
void endTransfer();
|
||||
|
||||
|
||||
DialogSocket* _pControlSocket = nullptr;
|
||||
SocketStream* _pDataStream = nullptr;
|
||||
|
||||
private:
|
||||
FTPClientSession(const FTPClientSession&);
|
||||
FTPClientSession& operator = (const FTPClientSession&);
|
||||
|
||||
|
||||
std::string _host;
|
||||
Poco::UInt16 _port;
|
||||
DialogSocket* _pControlSocket;
|
||||
SocketStream* _pDataStream;
|
||||
bool _passiveMode;
|
||||
FileType _fileType;
|
||||
bool _supports1738;
|
||||
bool _serverReady;
|
||||
bool _isLoggedIn;
|
||||
Poco::Timespan _timeout;
|
||||
Poco::UInt16 _port = 0;
|
||||
bool _passiveMode = true;
|
||||
FileType _fileType = TYPE_BINARY;
|
||||
bool _supports1738 = true;
|
||||
bool _serverReady = false;
|
||||
bool _isLoggedIn = false;
|
||||
Poco::Timespan _timeout = DEFAULT_TIMEOUT;
|
||||
};
|
||||
|
||||
|
||||
@@ -398,6 +404,10 @@ inline bool FTPClientSession::isLoggedIn() const
|
||||
return _isLoggedIn;
|
||||
}
|
||||
|
||||
inline bool FTPClientSession::isSecure() const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
} } // namespace Poco::Net
|
||||
|
||||
|
||||
@@ -31,9 +31,9 @@ namespace Net {
|
||||
|
||||
|
||||
FTPClientSession::FTPClientSession():
|
||||
_port(0),
|
||||
_pControlSocket(0),
|
||||
_pDataStream(0),
|
||||
_port(0),
|
||||
_passiveMode(true),
|
||||
_fileType(TYPE_BINARY),
|
||||
_supports1738(true),
|
||||
@@ -45,10 +45,10 @@ FTPClientSession::FTPClientSession():
|
||||
|
||||
|
||||
FTPClientSession::FTPClientSession(const StreamSocket& socket):
|
||||
_host(socket.address().host().toString()),
|
||||
_port(socket.address().port()),
|
||||
_pControlSocket(new DialogSocket(socket)),
|
||||
_pDataStream(0),
|
||||
_host(socket.address().host().toString()),
|
||||
_port(socket.address().port()),
|
||||
_passiveMode(true),
|
||||
_fileType(TYPE_BINARY),
|
||||
_supports1738(true),
|
||||
@@ -64,10 +64,10 @@ FTPClientSession::FTPClientSession(const std::string& host,
|
||||
Poco::UInt16 port,
|
||||
const std::string& username,
|
||||
const std::string& password):
|
||||
_host(host),
|
||||
_port(port),
|
||||
_pControlSocket(new DialogSocket(SocketAddress(host, port))),
|
||||
_pDataStream(0),
|
||||
_host(host),
|
||||
_port(port),
|
||||
_passiveMode(true),
|
||||
_fileType(TYPE_BINARY),
|
||||
_supports1738(true),
|
||||
@@ -75,10 +75,9 @@ FTPClientSession::FTPClientSession(const std::string& host,
|
||||
_isLoggedIn(false),
|
||||
_timeout(DEFAULT_TIMEOUT)
|
||||
{
|
||||
_pControlSocket->setReceiveTimeout(_timeout);
|
||||
if (!username.empty())
|
||||
login(username, password);
|
||||
else
|
||||
_pControlSocket->setReceiveTimeout(_timeout);
|
||||
}
|
||||
|
||||
|
||||
@@ -93,7 +92,6 @@ FTPClientSession::~FTPClientSession()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void FTPClientSession::setTimeout(const Poco::Timespan& timeout)
|
||||
{
|
||||
if (!isOpen())
|
||||
@@ -141,6 +139,17 @@ void FTPClientSession::open(const std::string& host,
|
||||
}
|
||||
}
|
||||
|
||||
void FTPClientSession::receiveServerReadyReply()
|
||||
{
|
||||
if (_serverReady)
|
||||
return;
|
||||
std::string response;
|
||||
int status = _pControlSocket->receiveStatusMessage(response);
|
||||
if (!isPositiveCompletion(status))
|
||||
throw FTPException("Cannot receive status message", response, status);
|
||||
|
||||
_serverReady = true;
|
||||
}
|
||||
|
||||
void FTPClientSession::login(const std::string& username, const std::string& password)
|
||||
{
|
||||
@@ -153,15 +162,7 @@ void FTPClientSession::login(const std::string& username, const std::string& pas
|
||||
_pControlSocket = new DialogSocket(SocketAddress(_host, _port));
|
||||
_pControlSocket->setReceiveTimeout(_timeout);
|
||||
}
|
||||
|
||||
if (!_serverReady)
|
||||
{
|
||||
status = _pControlSocket->receiveStatusMessage(response);
|
||||
if (!isPositiveCompletion(status))
|
||||
throw FTPException("Cannot login to server", response, status);
|
||||
|
||||
_serverReady = true;
|
||||
}
|
||||
receiveServerReadyReply();
|
||||
|
||||
status = sendCommand("USER", username, response);
|
||||
if (isPositiveIntermediate(status))
|
||||
@@ -593,5 +594,4 @@ void FTPClientSession::endTransfer()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} } // namespace Poco::Net
|
||||
|
||||
Reference in New Issue
Block a user