SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Jun 2014
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Post Want to connect Phpseclib/SSH Tunnel connect MYSQL server

    I want to connect to my remote Mysql server through port forwarding. Unfortunately Hostso.com my hosting provider don't have php_ssh2 installed on the server so I have to work through phpseclib library. So far I am able to do:
    1. Connect to server using Net_SSH2

    $ssh = new Net_SSH2('xx.xxx.xx.xx');
    if (!$ssh->login('user', 'password')) {
    exit('Login Failed');
    }

    If I do

    echo $ssh->exec('ls -la');it fetches directory listing telling we are connected successfully.

    if I run

    1. echo $ssh->exec('echo "select * from table where company_id=\"15\";" | mysql');It triggers:
    stdin: is not a tty ERROR 1045 (28000): Access denied for user 'user'@'localhost' (using password: NO)

    1. If I do
    echo $ssh->exec('ssh -f -L 3307:localhost:3306 root@xx.xxx.xxx.xxx sleep 60 >> logfile');It run forever and then resulting in no response error from the server.

    Please help me to resolve this issue or else I am thinking to switch to HostMonster.com or Waxspace.com or Dollar2host.com .. Please I need your support. I am in trouble.

  2. #2
    SitePoint Member
    Join Date
    Jun 2014
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    echo $ssh->exec('echo "select * from table where company_id=\"15\";" | mysql');
    Try this instead:

    Code:
    echo $ssh->exec('echo "select * from table where company_id=\"15\";" | mysql -u username --p=password');
    That of course assumes that the SQL server is on localhost and on port 3306.

    Code:
    echo $ssh->exec('ssh -f -L 3307:localhost:3306 root@xx.xxx.xxx.xxx sleep 60 >> logfile');
    You'd probably need to do nohup or & or some combination thereof. Also you might have better luck with $ssh->write() / $ssh->read() from phpseclib:

    http://phpseclib.sourceforge.net/ssh...ml#interactive

  3. #3
    SitePoint Member
    Join Date
    Jun 2014
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by spartica View Post
    Code:
    echo $ssh->exec('echo "select * from table where company_id=\"15\";" | mysql');
    Try this instead:

    Code:
    echo $ssh->exec('echo "select * from table where company_id=\"15\";" | mysql -u username --p=password');
    That of course assumes that the SQL server is on localhost and on port 3306.

    Code:
    echo $ssh->exec('ssh -f -L 3307:localhost:3306 root@xx.xxx.xxx.xxx sleep 60 >> logfile');
    You'd probably need to do nohup or & or some combination thereof. Also you might have better luck with $ssh->write() / $ssh->read() from phpseclib:

    http://phpseclib.sourceforge.net/ssh...ml#interactive

    Its working flwalessly now, my ronald from waxspace helped me to work on it. Nonetheless thank you for solution.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •