473,326 Members | 2,438 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

How to use php_ssh2 to connect a linux service through a relay swich

firstly, I connect to a relay switch:
Expand|Select|Wrap|Line Numbers
  1. $connection = ssh2_connect('Relay.com', 22);
  2. if (!$connection)
  3. {
  4.     die("Connection failed");
  5. }
  6. else
  7. {
  8.     echo "connect OK";
  9. }
  10.  
  11. if (!ssh2_auth_password($connection, 'username', 'password'))
  12. {
  13.     die("Auth failed");
  14. }
  15. else
  16. {
  17.     echo "login OK";
  18. }
then I ssh the linux service by:
Expand|Select|Wrap|Line Numbers
  1. $cmd="ssh root@10.*.*.*";
  2. ssh2_exec($connection,$cmd);
  3. sleep(10);
  4. $cmd="spassword";
  5. ssh2_exec($connection,$cmd);
After running, the output is :
connect OKlogin OK
Warning: ssh2_exec(): Unable to request command execution on remote host
Oct 19 '15 #1
1 1122
Dormilich
8,658 Expert Mod 8TB
you’re trying to execute a command on the wrong remote server. the connection resource points to Relay.com, but with your first exec call you have moved to 10.*.*.*, which is a different server. ssh2_exec() expects you to operate on the server opened by ssh2_connect().
Oct 20 '15 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Brad Clements | last post by:
I'm trying to get a simple service to work with py2exe and python 2.3 I get this error when I start it (after registering it) The description for Event ID ( 240 ) in Source ( UMXWIN32SVC )...
1
by: Suman | last post by:
We are facing a problem with a Service we developed. It does not start after a re-boot. We can Start/Stop the service from the interfacing Application and the Services Control Panel all day long....
1
by: Mike Stephens | last post by:
I would like to write a service app, a simple application that runs in the background and does its thing, and not necessarily running on the local machine. This service app will not have any GUI...
7
by: theGerm | last post by:
Is it possible for me to restart a service with PHP? I need to run this from a webpage /sbin/service squid reload
2
by: wph101larrya | last post by:
I have a developed service and client application running on a Vista machine in IIS7 in the Visual Studio 2008 beta 2 with .NET 3.5 framework. I am trying to deploy the service app to a test...
0
by: vedika | last post by:
hi, I have one c# application through which i connect to web service. web service is SSL protected. when i connect it through secure wireless network it is working well. but when i try to connect...
0
DB2 Warlord
by: DB2 Warlord | last post by:
After countless time I was unabl to find the answer to my HADR questions and getting HADR to work in 9.5 via the Control Center. Please see my fix that seem strange but works. My error was as...
1
by: Khadr Sarhan | last post by:
I have an client application and server application, I want to make an update program, In my program I want client send a message to server if there is an new version or not, and server reply with...
0
by: belltric | last post by:
I have a web service application project which need to deploy in production server(windows server 2008 r2 standard) and UAT server(web server). One of my web service in the web service application...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.