Jump to content

Recommended Posts

I am using the http://phpseclib.sourceforge.net/

 

and I able to connect to a Unix prompt and login. After login if I send

 


echo $ssh->exec('pwd');

 

it returns the directory I am in as it should.

 

but when I send this, a command on the box to change db instances.

 


echo $ssh->write("csession instance1 \n");

 

It just returns a 1.

 

What does the 1 mean?

 

Second question, how can I show what the prompt is returning?

 

I tried

 


echo $ssh->read('[prompt]');

 

but it fails, I also tried (with changed values for username@password)

 


$output = $ssh->read('#Password:|username@password:~\$#', NET_SSH2_READ_REGEX);
echo $output;

 

and that failed as well.

 

Does anyone know what the 1 means and how I could read the return prompt after sending a command?

 

Thanks,

sanchez

Link to comment
https://forums.phpfreaks.com/topic/262445-ssh2/
Share on other sites

Looks like you posted this question on the phpseclib support forums:

 

http://www.frostjedi.com/phpbb/viewtopic.php?p=156917#p156917

 

Do you not know what the prompt is?  If so you can do this to figure it out:

 

<?php
include('Net/SSH2.php');

$ssh = new Net_SSH2('www.domain.tld');
if (!$ssh->login('username', 'password')) {
    exit('Login Failed');
}

$ssh->setTimeout(5);
echo $ssh->read();
?>

Link to comment
https://forums.phpfreaks.com/topic/262445-ssh2/#findComment-1345217
Share on other sites

Thanks for your help. My post is also on Frost Jedi.

 

But when I tried the code you recommended i received this error in the log for the timeout call:

[14-May-2012 14:40:57 UTC] PHP Fatal error:  Call to undefined method Net_SSH2::setTimeout() in C:\inetpub\test\testssh6.php on line 8

 

if I comment that out, I receive this:

[14-May-2012 14:36:21 UTC] PHP Warning:  Missing argument 1 for Net_SSH2::read(), called in C:\inetpub\test\testssh6.php on line 9 and defined in C:\inetpub\test\phpseclib0.2.2\Net\SSH2.php on line 1768

[14-May-2012 14:36:21 UTC] PHP Notice:  Undefined variable: expect in C:\inetpub\test\phpseclib0.2.2\Net\SSH2.php on line 1780

 

Thanks,

sanchez

Link to comment
https://forums.phpfreaks.com/topic/262445-ssh2/#findComment-1345329
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.