Skip to content

Commit

Permalink
feat(FTPClientSession): activeDataConnection 1.11.0 cannot set specif…
Browse files Browse the repository at this point in the history
…ic data port #3372
  • Loading branch information
aleks-f committed Jun 23, 2022
1 parent 391cb63 commit c8e6602
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
10 changes: 7 additions & 3 deletions Net/include/Poco/Net/FTPClientSession.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,18 +58,21 @@ class Net_API FTPClientSession
TYPE_BINARY /// TYPE I (Image/binary data)
};

FTPClientSession();
FTPClientSession(Poco::UInt16 activeDataPort = 0);
/// Creates an FTPClientSession.
///
/// Passive mode will be used for data transfers.

FTPClientSession(const StreamSocket& socket, bool readWelcomeMessage = true);
FTPClientSession(const StreamSocket& socket, bool readWelcomeMessage = true,
Poco::UInt16 activeDataPort = 0);
/// Creates an FTPClientSession using the given
/// connected socket for the control connection.
///
/// Passive mode will be used for data transfers.

FTPClientSession(const std::string& host, Poco::UInt16 port = FTP_PORT, const std::string& username = "", const std::string& password = "");
FTPClientSession(const std::string& host, Poco::UInt16 port = FTP_PORT,
const std::string& username = "", const std::string& password = "",
Poco::UInt16 activeDataPort = 0);
/// Creates an FTPClientSession using a socket connected
/// to the given host and port. If username is supplied,
/// login is attempted.
Expand Down Expand Up @@ -350,6 +353,7 @@ class Net_API FTPClientSession

std::string _host;
Poco::UInt16 _port = FTP_PORT;
Poco::UInt16 _activeDataPort = 0;
bool _passiveMode = true;
FileType _fileType = TYPE_BINARY;
bool _supports1738 = true;
Expand Down
14 changes: 10 additions & 4 deletions Net/src/FTPClientSession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,11 @@ namespace Poco {
namespace Net {


FTPClientSession::FTPClientSession():
FTPClientSession::FTPClientSession(Poco::UInt16 activeDataPort):
_pControlSocket(0),
_pDataStream(0),
_port(FTP_PORT),
_activeDataPort(activeDataPort),
_passiveMode(true),
_fileType(TYPE_BINARY),
_supports1738(true),
Expand All @@ -42,11 +43,14 @@ FTPClientSession::FTPClientSession():
}


FTPClientSession::FTPClientSession(const StreamSocket& socket, bool readWelcomeMessage):
FTPClientSession::FTPClientSession(const StreamSocket& socket,
bool readWelcomeMessage,
Poco::UInt16 activeDataPort):
_pControlSocket(new DialogSocket(socket)),
_pDataStream(0),
_host(socket.address().host().toString()),
_port(socket.address().port()),
_activeDataPort(activeDataPort),
_passiveMode(true),
_fileType(TYPE_BINARY),
_supports1738(true),
Expand All @@ -69,11 +73,13 @@ FTPClientSession::FTPClientSession(const StreamSocket& socket, bool readWelcomeM
FTPClientSession::FTPClientSession(const std::string& host,
Poco::UInt16 port,
const std::string& username,
const std::string& password):
const std::string& password,
Poco::UInt16 activeDataPort):
_pControlSocket(new DialogSocket(SocketAddress(host, port))),
_pDataStream(0),
_host(host),
_port(port),
_activeDataPort(activeDataPort),
_passiveMode(true),
_fileType(TYPE_BINARY),
_supports1738(true),
Expand Down Expand Up @@ -452,7 +458,7 @@ StreamSocket FTPClientSession::activeDataConnection(const std::string& command,
if (!isOpen())
throw FTPException("Connection is closed.");

ServerSocket server(SocketAddress(_pControlSocket->address().host(), 0));
ServerSocket server(SocketAddress(_pControlSocket->address().host(), _activeDataPort));
sendPortCommand(server.address());
std::string response;
int status = sendCommand(command, arg, response);
Expand Down

0 comments on commit c8e6602

Please sign in to comment.