|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2012-10-07 19:29 UTC] langemeijer@php.net
Description:
------------
Please consider this:
$Channel = ssh2_command_channel ( resource $session [, string $term_type =
"vanilla" [, array $env [, int$width = 80 [, int $height = 25 [, int
$width_height_type = SSH2_TERM_UNIT_CHARS ]]]]] );
$retval = $Channel->execute ('/usr/bin/fsck', &$stdout, &$stderr, $stdin);
$Channel->setenv('key', 'value');
...
$Channel->execute(....);
unset($Channel); // Closes the channel.
This way executing a command is easy:
- A blocking execute call,
- No reading of or writing to streams,
- Able to get the return value of an executable in an easy way
It would not be ideal if you have big amounts of data flowing in stdin/stdout,
but for a lot of use-cases this would be much easier.
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Tue Oct 28 20:00:01 2025 UTC |
Correct me if I'm wrong but does this do what you're wanting?: <?php include('Net/SSH2.php'); $ssh = new Net_SSH2('www.domain.tld'); if (!$ssh->login('username', 'password')) { exit('Login Failed'); } echo $ssh->exec('pwd'); echo $ssh->exec('ls -la'); ?> (using phpseclib's Net_SSH2)zelnaga - Is that library you are referencing the same as the one for this bug? Currently ssh2 (PECL) closes the channel after each ssh2_exec or ssh2_shell. So with this current way, things that you had previously done aren't kept. If you were to run a command get the results with a shell variable and then the next command uses that variable, the variable would be lost as an example. This enhancement reuses the same channel for each command. In your example I would change the exec to: echo $ssh->exec('cd ./newdirectory'); echo $ssh->exec('ls -la'); ls -la currently would show the directory above newdirectory. This enhancement would allow ls -la to show ./newdirectory. The current workaround for this would be: echo $ssh->exec('cd ./newdirectory && ls -la');