GithubHelp home page GithubHelp logo

php-ssh's Introduction

PHP SSH

Provides an object-oriented wrapper for the php ssh2 extension.

Requirements

You need PHP version 5.3+ with the SSH2 extension.

Installation

Download the php-ssh library files in your project. If your project is versioned using git, the best is to add it as a submodule:

$ git submodule add https://github.com/Herzult/php-ssh.git vendor/php-ssh

Then, you must add it to your autoloader. If you have no autoloader, you can use the one provided with the library. Here is an exemple of how to use it:

<?php

require_once __DIR__.'/vendor/php-ssh/src/ClassLoader/UniversalClassLoader.php';

use ClassLoader\UniversalClassLoader;

$loader = new UniversalClassLoader();
$loader->registerNamespaces(array(
    'Ssh' => __DIR__.'/vendor/php-ssh/src'
));

$loader->register();

Installation (via composer)

Download composer. Install php-ssh using composer:

$ php composer.phar install

Usage

Configuration of the connection

To etablish an SSH connection, you must firt define its configuration. For that, create a Configuration instance with all the needed parameters.

<?php

// simple configuration to connect "my-host"
$configuration = new Ssh\Configuration('my-host');

Create a session

The session is the central access point to the SSH functionality provided by the library.

<?php

// ... the configuration creation

$session = new Ssh\Session($configuration);

Authentication

The authentication classes allow you to authenticate over a SSH session. When you define an authentication for a session, it will authenticate on connection.

<?php

$configuration = new Ssh\Configuration('myhost');
$authentication = new Ssh\Authentication\Password('John', 's3cr3t');

$session = new Session($configuration, $authentication);

The available authentication are:

  • None for username based authentication
  • Password for password authentication
  • PublicKeyFile to authenticate using a public key
  • HostBasedFile to authenticate using a public hostkey
  • Agent to authenticate using an ssh-agent

Subsystems

Once you are authenticated over a SSH session, you can use the subsystems.

Sftp

You can easily access the sftp subsystem of a session using the getSftp() method:

<?php

// the session creation

$sftp = $session->getSftp();

See the Ssh\Sftp class for more details on the available methods.

Publickey

The session provides also the getPublickey() method to access the publickey subsystem:

<?php

// ... the session creation

$publickey = $session->getPublickey();

See the Ssh\Publickey class for more details on the available methods.

php-ssh's People

Contributors

herzult avatar ddeboer avatar awildeep avatar l3l0 avatar yvalentin avatar

Watchers

Cam Spiers avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.