ssh2_exec
(PECL ssh2 >= 0.9.0)
ssh2_exec — リモートサーバー上でコマンドを実行する
説明
resource ssh2_exec
( resource
$session
, string $command
[, string $pty
[, array $env
[, int $width = 80
[, int $height = 25
[, int $width_height_type = SSH2_TERM_UNIT_CHARS
]]]]] )コマンドをリモートエンドで実行し、チャネルを割り当てます。
パラメータ
-
session -
ssh2_connect() のコールによって取得した SSH 接続リンク ID。
-
command -
-
pty -
-
env -
envには、 対象となる環境で設定する名前/値のペアを連想配列で渡します。 -
width -
仮想端末の幅。
-
height -
仮想端末の高さ。
-
width_height_type -
width_height_typeは、SSH2_TERM_UNIT_CHARSあるいはSSH2_TERM_UNIT_PIXELSのいずれかです。
返り値
成功時にストリームを返し、失敗した場合に FALSE を返します。
例
例1 コマンドの実行
<?php
$connection = ssh2_connect('shell.example.com', 22);
ssh2_auth_password($connection, 'username', 'password');
$stream = ssh2_exec($connection, '/usr/local/bin/php -i');
?>
参考
- ssh2_connect() - SSH サーバーに接続する
- ssh2_shell() - 対話式のシェルを要求する
- ssh2_tunnel() - リモートサーバーを経由するトンネルをオープンする