Ticket #4806: SSH-tunneling.patch

File SSH-tunneling.patch, 1.2 KB (added by db8200, 12 years ago)

Same code as in the description, patch created with svn diff.

  • src/engine/ftpcontrolsocket.cpp

     
    1010#include "tlssocket.h"
    1111#include "pathcache.h"
    1212#include <algorithm>
     13#include <signal.h>
     14#include <sys/wait.h>
    1315#include <wx/tokenzr.h>
    1416#include "local_filesys.h"
    1517#include <errno.h>
     
    38073809        }
    38083810    }
    38093811
     3812    // Create an SSH tunnel on the port specified by the server for the passive data connection
     3813    int error = 0;
     3814    static int tunnelPID = 0;
     3815    if( m_pSocket->GetRemotePort(error) == 2121 ) // I use this port only for SSH tunneling
     3816    {
     3817        if ( tunnelPID )
     3818        {
     3819            kill( tunnelPID, 15 ); // SIGTERM (include signal.h)
     3820            waitpid( tunnelPID, &error, 0 ); // (include sys/wait.h)
     3821        }
     3822        wxString portFw = wxString::Format("%d:%s:%d", pData->port, pData->host.c_str(), pData->port);
     3823        if ( !( tunnelPID = fork() ) )
     3824            execlp("ssh", "ssh", "-L", portFw.c_str(), "myuser@myproxyserver.fr", "-N", "-n", NULL);
     3825        pData->host = peerIP; // Connect to localhost (SSH tunnel), not to the specified IP
     3826        sleep(4); // myproxyserver is somewhat slow to create the tunnel
     3827    }
     3828
    38103829    return true;
    38113830}
    38123831