Hello there i´m new to this and sorry for my bad englisch but I don´t know any other ways to solve my problem.
I´m uploading files using Poco NetSSL Library (uses OpenSSL) in C++ to a PureFTP Server.
Using the newest version of Poco Library and OpenSSL, in Visual Studio 2020.
I can establish a correct SSL connection to the server, and upload many Files, but after approx. 200 Files ( the file size and file type is totally unimportant, i´ve found out ) the connection closes and the SSL connection unexpectedly closed.
Poco::Net::SSLConnectionUnexpectedlyClosedException
Poco Library Docs to this Error
This Error occurs only on other machines, not on mine, where i coded the class. It´s unimportant if i try the .exe File or I compile it with Visual Studio 2020 (release or debug, unimportant).
The server settings are set corrctly i think:
The idle_time is set to 50 min +, and other restrictions aren´t set.
Our Main: Main.cpp
#include "FTPS.h"
int main() {
FTPS ftps = FTPS();
std::string path;
std::cout << "Enter upload path:" << std::endl;
std::cin >> path;
ftps.INITUpload(path);
system("pause");
return 0;
}
This is the header of the FTPS class:
FTPS.h
#include <Poco/Net/FTPClientSession.h>
#include <Poco/Net/FTPSClientSession.h>
#include <Poco/Net/NetException.h>
#include <Poco/File.h>
#include <Poco/FileStream.h>
#include <Poco/DirectoryIterator.h>
#include <Poco/Net/SSLManager.h>
#include <Poco/Net/AcceptCertificateHandler.h>
class FTPS{
private:
Poco::Net::FTPSClientSession *FTPSClient;
void Upload(const std::string& path);
public:
//Constructer/Destructer
FTPS();
virtual ~FTPS();
//Functions
void INITUpload(const std::string& path);
};
This is the main part of the class:
FTPS.cpp
#include "FTPS.h"
//Constructer/Destructer
FTPS::FTPS() {
try {
Poco::Net::initializeSSL();
Poco::Net::SSLManager::InvalidCertificateHandlerPtr ptrHandler(new Poco::Net::AcceptCertificateHandler(false));
const Poco::Net::Context::Ptr context = new Poco::Net::Context(
Poco::Net::Context::CLIENT_USE, "", "", "",
Poco::Net::Context::VERIFY_NONE, 9, false,
"ALL:!ADH:!LOW:!EXP:!MD5:@STRENGTH");
Poco::Net::SSLManager::instance().initializeClient(0, ptrHandler, context);
Poco::Net::StreamSocket socket = Poco::Net::StreamSocket(Poco::Net::SocketAddress("hostname:21"));
FTPSClient = new Poco::Net::FTPSClientSession(socket, context);
FTPSClient->login("asdf","01234");
std::cout << FTPSClient->welcomeMessage() << std::endl;
}
catch (const Poco::Exception& e) {
std::cout << e.message() << std::endl;
}
}
FTPS::~FTPS()
{
}
//Functions
void FTPS::Upload(const std::string& path) {
std::string dst = Poco::Path(path).getFileName();
try {
if (!Poco::File(path).isDirectory()) {
std::string temp = Poco::Path(path).toString(Poco::Path::PATH_UNIX);
Poco::FileInputStream fstream(path);
std::cout << path << std::endl;
std::ostream& data = FTPSClient->beginUpload(dst);
data << fstream.rdbuf();
FTPSClient->endUpload();
}
else {
FTPSClient->createDirectory(dst);
FTPSClient->setWorkingDirectory(dst);
for (Poco::DirectoryIterator dit(path); !dit.name().empty(); ++dit) {
this->Upload(dit.path().toString());
}
}
}
catch (Poco::Exception& e) {
std::cout << e.message() << std::endl;
}
}
void FTPS::INITUpload(const std::string& path) {
this->Upload(path);
}
And yes, I know that the Verify_None is set, this is a little issue we have with the the servers certificate, because Poco wants to use as the cercificate owner the ip of the server, but our certificate is set to the domain.
Please login or Register to submit your answer