FTPSClientSession.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. //
  2. // FTPSClientSession.h
  3. //
  4. // Library: Net
  5. // Package: FTP
  6. // Module: FTPSClientSession
  7. //
  8. // Definition of the FTPSClientSession class.
  9. //
  10. // Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
  11. // and Contributors.
  12. //
  13. // SPDX-License-Identifier: BSL-1.0
  14. //
  15. #ifndef NetSSL_FTPSClientSession_INCLUDED
  16. #define NetSSL_FTPSClientSession_INCLUDED
  17. #include "Poco/Net/NetSSL.h"
  18. #include "Poco/Net/FTPClientSession.h"
  19. namespace Poco {
  20. namespace Net {
  21. class NetSSL_API FTPSClientSession: public Poco::Net::FTPClientSession
  22. {
  23. public:
  24. FTPSClientSession();
  25. /// Creates an FTPSClientSession.
  26. ///
  27. /// Passive mode will be used for data transfers.
  28. explicit FTPSClientSession(const StreamSocket& socket, bool readWelcomeMessage = true, bool tryUseFTPS = true);
  29. /// Creates an FTPSClientSession using the given
  30. /// connected socket for the control connection.
  31. ///
  32. /// Passive mode will be used for data transfers.
  33. FTPSClientSession(const std::string& host, Poco::UInt16 port = FTP_PORT, const std::string& username = "", const std::string& password = "");
  34. /// Creates an FTPSClientSession using a socket connected
  35. /// to the given host and port. If username is supplied,
  36. /// login is attempted.
  37. ///
  38. /// Passive mode will be used for data transfers.
  39. virtual ~FTPSClientSession();
  40. void tryFTPSmode(bool tryFTPS);
  41. /// avoid or require TLS mode
  42. bool isSecure() const;
  43. /// Returns true if the session is FTPS.
  44. protected:
  45. virtual StreamSocket establishDataConnection(const std::string& command, const std::string& arg);
  46. /// Create secure data connection
  47. virtual void receiveServerReadyReply();
  48. /// Function that read server welcome message after connetion and set and make secure socket
  49. private:
  50. void beforeCreateDataSocket();
  51. ///Send commands to check if we can encrypt data socket
  52. void afterCreateControlSocket();
  53. ///Send commands to make SSL negotiating of control channel
  54. bool _tryFTPS = true;
  55. bool _secureDataConnection = false;
  56. };
  57. //
  58. // inlines
  59. //
  60. inline bool FTPSClientSession::isSecure() const
  61. {
  62. if (_pControlSocket != nullptr)
  63. return _pControlSocket->secure();
  64. return false;
  65. }
  66. } } // namespace Poco::Net
  67. #endif // #define NetSSL_FTPSClientSession_INCLUDED