rannk/php-interactive-ssh

提供交互式SSH连接。

dev-master 2014-11-07 06:55 UTC

This package is not auto-updated.

Last update: 2024-09-24 03:49:17 UTC


README

提供交互式SSH连接。

要求

您需要一个支持SSH2扩展的PHP 5.3+版本。

安装

将库添加到项目的最佳方式是使用composer

$ composer require rannk/php-interactive-ssh:dev-master

使用方法

这个包装工具非常易于使用。但目前我们仅提供使用用户名和密码来访问SSH连接。

如何使用它

步骤 1: 实例化一个连接对象

<?php
$conn = new ssh\Connection(hostname, [port]);
$conn->authByPassword(username, password);

步骤 2: 创建一个会话

<?php
$session = $conn->createSession();

步骤 3: 发送您的命令

<?php
$session->expect('$');
$session->send('ls');
$session->expect('$');

方法说明

session::expect(expect_word, expire_time, display_message) 返回 String

expect_word(String):  which word you expected waiting for when you want to run next command

expire_time(int): The default is 0. set the waiting for time. The zero mean always wait.

display_message(boolean): To set true is mean display the output message that from command. 

session::send(command) 返回 void

command(String): The shell command