diff --git a/fineftp-server/src/filesystem.cpp b/fineftp-server/src/filesystem.cpp index 6de5182..e0a51c8 100644 --- a/fineftp-server/src/filesystem.cpp +++ b/fineftp-server/src/filesystem.cpp @@ -297,7 +297,7 @@ namespace Filesystem hFind = FindFirstFileW(w_find_file_path.c_str(), &ffd); if (hFind == INVALID_HANDLE_VALUE) { - std::cerr << "FindFirstFile Error" << std::endl; + error_ << "FindFirstFile Error" << std::endl; return content; } @@ -312,7 +312,7 @@ namespace Filesystem struct dirent *dirp = nullptr; if(dp == nullptr) { - std::cerr << "Error opening directory: " << strerror(errno) << std::endl; + error << "Error opening directory: " << strerror(errno) << std::endl; return content; } diff --git a/fineftp-server/src/ftp_session.cpp b/fineftp-server/src/ftp_session.cpp index 168133d..42f803b 100755 --- a/fineftp-server/src/ftp_session.cpp +++ b/fineftp-server/src/ftp_session.cpp @@ -57,7 +57,7 @@ namespace fineftp FtpSession::~FtpSession() { #ifndef NDEBUG - std::cout << "Ftp Session shutting down" << std::endl; + output_ << "Ftp Session shutting down" << std::endl; #endif // !NDEBUG { @@ -87,7 +87,7 @@ namespace fineftp { asio::error_code ec; command_socket_.set_option(asio::ip::tcp::no_delay(true), ec); - if (ec) std::cerr << "Unable to set socket option tcp::no_delay: " << ec.message() << std::endl; + if (ec) error_ << "Unable to set socket option tcp::no_delay: " << ec.message() << std::endl; command_strand_.post([me = shared_from_this()]() { me->readFtpCommand(); }); sendFtpMessage(FtpMessage(FtpReplyCode::SERVICE_READY_FOR_NEW_USER, "Welcome to fineFTP Server")); @@ -123,7 +123,7 @@ namespace fineftp void FtpSession::startSendingMessages() { #ifndef NDEBUG - std::cout << "FTP >> " << command_output_queue_.front() << std::endl; + output_ << "FTP >> " << command_output_queue_.front() << std::endl; #endif asio::async_write(command_socket_ @@ -152,7 +152,7 @@ namespace fineftp } else { - std::cerr << "Command write error for message " << me->command_output_queue_.front() << ec.message() << std::endl; + me->error_ << "Command write error for message " << me->command_output_queue_.front() << ec.message() << std::endl; } } )); @@ -167,12 +167,12 @@ namespace fineftp { if (ec != asio::error::eof) { - std::cerr << "read_until error: " << ec.message() << std::endl; + me->error_ << "read_until error: " << ec.message() << std::endl; } #ifndef NDEBUG else { - std::cout << "Control connection closed by client." << std::endl; + me->output_ << "Control connection closed by client." << std::endl; } #endif // !NDEBUG // Close the data connection, if it is open @@ -200,7 +200,7 @@ namespace fineftp stream.ignore(2); // Remove the "\r\n" #ifndef NDEBUG - std::cout << "FTP << " << packet_string << std::endl; + me->output_ << "FTP << " << packet_string << std::endl; #endif me->handleFtpCommand(packet_string); @@ -414,7 +414,7 @@ namespace fineftp data_acceptor_.close(ec); if (ec) { - std::cerr << "Error closing data acceptor: " << ec.message() << std::endl; + error_ << "Error closing data acceptor: " << ec.message() << std::endl; } } @@ -425,7 +425,7 @@ namespace fineftp data_acceptor_.open(endpoint.protocol(), ec); if (ec) { - std::cerr << "Error opening data acceptor: " << ec.message() << std::endl; + error_ << "Error opening data acceptor: " << ec.message() << std::endl; sendFtpMessage(FtpReplyCode::SERVICE_NOT_AVAILABLE, "Failed to enter passive mode."); return; } @@ -435,7 +435,7 @@ namespace fineftp data_acceptor_.bind(endpoint, ec); if (ec) { - std::cerr << "Error binding data acceptor: " << ec.message() << std::endl; + error_ << "Error binding data acceptor: " << ec.message() << std::endl; sendFtpMessage(FtpReplyCode::SERVICE_NOT_AVAILABLE, "Failed to enter passive mode."); return; } @@ -445,7 +445,7 @@ namespace fineftp data_acceptor_.listen(asio::socket_base::max_connections, ec); if (ec) { - std::cerr << "Error listening on data acceptor: " << ec.message() << std::endl; + error_ << "Error listening on data acceptor: " << ec.message() << std::endl; sendFtpMessage(FtpReplyCode::SERVICE_NOT_AVAILABLE, "Failed to enter passive mode."); return; } @@ -1376,7 +1376,7 @@ namespace fineftp if (ec) { - std::cerr << "Data write error: " << ec.message() << std::endl; + me->error_ << "Data write error: " << ec.message() << std::endl; return; } @@ -1417,7 +1417,7 @@ namespace fineftp { if (ec) { - std::cerr << "Data transfer aborted: " << ec.message() << std::endl; + me->error_ << "Data transfer aborted: " << ec.message() << std::endl; me->sendFtpMessage(FtpReplyCode::TRANSFER_ABORTED, "Data transfer aborted"); return; } diff --git a/fineftp-server/src/server_impl.cpp b/fineftp-server/src/server_impl.cpp index 3faa6bb..d9def60 100644 --- a/fineftp-server/src/server_impl.cpp +++ b/fineftp-server/src/server_impl.cpp @@ -50,7 +50,7 @@ namespace fineftp const asio::ip::tcp::endpoint endpoint(asio::ip::make_address(address_, make_address_ec), port_); if (make_address_ec) { - std::cerr << "Error creating address from string \"" << address_<< "\": " << make_address_ec.message() << std::endl; + error_ << "Error creating address from string \"" << address_<< "\": " << make_address_ec.message() << std::endl; return false; } @@ -59,7 +59,7 @@ namespace fineftp acceptor_.open(endpoint.protocol(), ec); if (ec) { - std::cerr << "Error opening acceptor: " << ec.message() << std::endl; + error_ << "Error opening acceptor: " << ec.message() << std::endl; return false; } } @@ -69,7 +69,7 @@ namespace fineftp acceptor_.set_option(asio::ip::tcp::acceptor::reuse_address(true), ec); if (ec) { - std::cerr << "Error setting reuse_address option: " << ec.message() << std::endl; + error_ << "Error setting reuse_address option: " << ec.message() << std::endl; return false; } } @@ -79,7 +79,7 @@ namespace fineftp acceptor_.bind(endpoint, ec); if (ec) { - std::cerr << "Error binding acceptor: " << ec.message() << std::endl; + error_ << "Error binding acceptor: " << ec.message() << std::endl; return false; } } @@ -89,13 +89,13 @@ namespace fineftp acceptor_.listen(asio::socket_base::max_listen_connections, ec); if (ec) { - std::cerr << "Error listening on acceptor: " << ec.message() << std::endl; + error_ << "Error listening on acceptor: " << ec.message() << std::endl; return false; } } #ifndef NDEBUG - std::cout << "FTP Server created." << std::endl << "Listening at address " << acceptor_.local_endpoint().address() << " on port " << acceptor_.local_endpoint().port() << ":" << std::endl; + output_ << "FTP Server created." << std::endl << "Listening at address " << acceptor_.local_endpoint().address() << " on port " << acceptor_.local_endpoint().port() << ":" << std::endl; #endif // NDEBUG acceptor_.async_accept(ftp_session->getSocket() @@ -129,13 +129,13 @@ namespace fineftp if (error) { #ifndef NDEBUG - std::cerr << "Error handling connection: " << error.message() << std::endl; + error_ << "Error handling connection: " << error.message() << std::endl; #endif return; } #ifndef NDEBUG - std::cout << "FTP Client connected: " << ftp_session->getSocket().remote_endpoint().address().to_string() << ":" << ftp_session->getSocket().remote_endpoint().port() << std::endl; + output_ << "FTP Client connected: " << ftp_session->getSocket().remote_endpoint().address().to_string() << ":" << ftp_session->getSocket().remote_endpoint().port() << std::endl; #endif ftp_session->start(); diff --git a/fineftp-server/src/user_database.cpp b/fineftp-server/src/user_database.cpp index 8c3ec13..5fd1f22 100644 --- a/fineftp-server/src/user_database.cpp +++ b/fineftp-server/src/user_database.cpp @@ -25,14 +25,14 @@ namespace fineftp { if (anonymous_user_) { - std::cerr << "Error adding user with username \"" << username << "\". The username denotes the anonymous user, which is already present." << std::endl; + error_ << "Error adding user with username \"" << username << "\". The username denotes the anonymous user, which is already present." << std::endl; return false; } else { anonymous_user_ = std::make_shared(password, local_root_path, permissions); #ifndef NDEBUG - std::cout << "Successfully added anonymous user." << std::endl; + output_ << "Successfully added anonymous user." << std::endl; #endif // !NDEBUG return true; } @@ -44,13 +44,13 @@ namespace fineftp { database_.emplace(username, std::make_shared(password, local_root_path, permissions)); #ifndef NDEBUG - std::cout << "Successfully added user \"" << username << "\"." << std::endl; + output_ << "Successfully added user \"" << username << "\"." << std::endl; #endif // !NDEBUG return true; } else { - std::cerr << "Error adding user with username \"" << username << "\". The user already exists." << std::endl; + error_ << "Error adding user with username \"" << username << "\". The user already exists." << std::endl; return false; } }