• Skip to main content
  • Skip to primary sidebar
  • Skip to footer
  • About
  • Life
  • Tech
  • Travel
  • Work
  • Questions
  • Contact

Welcome

.

C++ FTPS Upload Client throws SSL Error: Poco::Net::SSLConnectionUnexpectedlyClosedException

April 10, 2020 by

Questions › C++ FTPS Upload Client throws SSL Error: Poco::Net::SSLConnectionUnexpectedlyClosedException
0
Vote Up
Vote Down
Garmaine asked 4 years ago

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.

Are you looking for the answer?
Original Question and Possible Answers can be found on `http://stackoverflow.com`

Question Tags: c++, c++17, poco, poco-libraries

Please login or Register to submit your answer




Primary Sidebar

Tags

Advancements best Business strategies commercial convenience economic Finances Cognitive decline Financial growth firm Future Hidden Gems Home hydration Impact Innovations lighting line of work Mental health Must-See New York City office patronage Productivity profession Profitability tips Profit optimization pursuit recreation Revenue enhancement romance sippy cups social station Technological breakthroughs technology toddlers trading transaction Treasures Uncover undertaking Well-being Wonders Work Young onset dementia

Newsletter

Complete the form below, and we'll send you all the latest news.

Footer

Footer Funnies

Who knew that reading the footer could be such a hilarious adventure? As we navigate websites, books, and documents, we often stumble upon the unassuming space at the bottom, only to discover a treasure trove of amusement. In this side-splitting compilation, we present 100 jokes that celebrate the unsung hero of content – the footer. Get ready to chuckle, giggle, and maybe even snort as we dive into the world of footnotes, disclaimers, and hidden comedic gems. Brace yourself for a wild ride through the footer!

Recent

  • Unveiling the Enigma: Almost-Magical Lamp Lights Highway Turns
  • The Impact of Young Onset Dementia on Employment and Finances: Optimizing Post-Diagnostic Approaches
  • 11 Wonders of 2023 Technological Breakthrough – Unveiling the Future
  • Work from Home and Stay Mentally Sane – Achieve Productivity and Well-being
  • Hidden Gems of New York City – Uncover the Must-See Treasures!

Search

Tags

Advancements best Business strategies commercial convenience economic Finances Cognitive decline Financial growth firm Future Hidden Gems Home hydration Impact Innovations lighting line of work Mental health Must-See New York City office patronage Productivity profession Profitability tips Profit optimization pursuit recreation Revenue enhancement romance sippy cups social station Technological breakthroughs technology toddlers trading transaction Treasures Uncover undertaking Well-being Wonders Work Young onset dementia

Copyright © 2023