diff --git a/RTCP/IONProc/src/SSH.cc b/RTCP/IONProc/src/SSH.cc
index dbbc16a7ff5ac0af947e60a35d8bb89c0d39eab1..dc2d734f785fcfb6adcb49870a3bd4e2bcb55e4f 100644
--- a/RTCP/IONProc/src/SSH.cc
+++ b/RTCP/IONProc/src/SSH.cc
@@ -35,6 +35,8 @@
 #include <string.h>
 #include <errno.h>
 #include <vector>
+#include <string>
+#include <sstream>
 
 #ifdef HAVE_LIBSSH2
 #include <Scheduling.h>
@@ -217,7 +219,6 @@ void SSHconnection::commThread()
 
   LOG_DEBUG_STR( itsLogPrefix << "Connected" );
 
-  stringstream buffer;
   int rc;
   int exitcode;
   char *exitsignal=(char *)"none";
@@ -247,16 +248,24 @@ void SSHconnection::commThread()
 
   LOG_DEBUG_STR( itsLogPrefix << "Remote command started, waiting for output" );
 
+  // raw input buffer
+  char data[0x1000];
+
+  // the current line (or line remnant)
+  string line("");
+
   /* Session I/O */
   for( ;; )
   {
     /* loop until we block */
     do {
-      char data[0x4000];
-
       rc = libssh2_channel_read( channel, data, sizeof data );
       if( rc > 0 )
       {
+        // create a buffer for line + data
+        stringstream buffer;
+
+        buffer << line;
         buffer.write( data, rc );
 
         /* extract and log lines */
@@ -264,16 +273,15 @@ void SSHconnection::commThread()
         {
           Cancellation::point();
 
-          buffer.getline( data, sizeof data );
+          std::getline( buffer, line );
 
-          if (buffer.fail()) {
-            // no line found
-            buffer.clear();
+          if (!buffer.good()) {
+            // 'line' now holds the remnant
             break;
           }
 
           // TODO: Use logger somehow (we'd duplicate the prefix if we just use LOG_* macros..)
-          cout << data << endl;
+          cout << line << endl;
         }
       } else {
         if( rc < 0 && rc != LIBSSH2_ERROR_EAGAIN ) {