2017 © Pedro Peláez
 

library ssh

Dazzle Asynchronous SSH.

image

dazzle-php/ssh

Dazzle Asynchronous SSH.

  • Sunday, July 23, 2017
  • by khelle
  • Repository
  • 1 Watchers
  • 8 Stars
  • 498 Installations
  • PHP
  • 2 Dependents
  • 0 Suggesters
  • 2 Forks
  • 1 Open issues
  • 5 Versions
  • 9 % Grown

The README.md

Dazzle Async SSH

Build Status Code Coverage Code Quality Latest Stable Version Latest Unstable Version License, (*1)

Note: This repository is part of Dazzle Project - the next-gen library for PHP. The project's purpose is to provide PHP developers with a set of complete tools to build functional async applications. Please, make sure you read the attached README carefully and it is guaranteed you will be surprised how easy to use and powerful it is. In the meantime, you might want to check out the rest of our async libraries in Dazzle repository for the full extent of Dazzle experience., (*2)


, (*3)

, (*4)

Description

Dazzle SSH is a component that provides consistent interface for PHP SSH2 extension and allows asynchronous writing and reading., (*5)

Feature Highlights

Dazzle SSH features:, (*6)

  • OOP abstraction for PHP SSH2 extension,
  • Support for variety of authorization methods,
  • Asynchronous SSH2 commands,
  • Asynchronous operations on files via SFTP,
  • ...and more.

Provided Example(s)

Executing commands

$loop   = new Loop(new SelectLoop);
$auth   = new SSH2Password($user, $pass);
$config = new SSH2Config();
$ssh2   = new SSH2($auth, $config, $loop);

$ssh2->on('connect:shell', function(SSH2DriverInterface $shell) use($ssh2, $loop) {
    echo "# CONNECTED SHELL\n";

    $buffer = '';
    $command = $shell->open();
    $command->write('ls -la');
    $command->on('data', function(SSH2ResourceInterface $command, $data) use(&$buffer) {
        $buffer .= $data;
    });
    $command->on('end', function(SSH2ResourceInterface $command) use(&$buffer) {
        echo "# COMMAND RETURNED:\n";
        echo $buffer;
        $command->close();
    });
    $command->on('close', function(SSH2ResourceInterface $command) use($shell) {
        $shell->disconnect();
    });
});

$ssh2->on('disconnect:shell', function(SSH2DriverInterface $shell) use($ssh2) {
    echo "# DISCONNECTED SHELL\n";
    $ssh2->disconnect();
});

$ssh2->on('connect', function(SSH2Interface $ssh2) {
    echo "# CONNECTED\n";
    $ssh2->createDriver(SSH2::DRIVER_SHELL)
         ->connect();
});

$ssh2->on('disconnect', function(SSH2Interface $ssh2) use($loop) {
    echo "# DISCONNECTED\n";
    $loop->stop();
});

$loop->onTick(function() use($ssh2) {
    $ssh2->connect();
});

$loop->start();

Writing files

$loop   = new Loop(new SelectLoop);
$auth   = new SSH2Password($user, $pass);
$config = new SSH2Config();
$ssh2   = new SSH2($auth, $config, $loop);

$ssh2->on('connect:sftp', function(SSH2DriverInterface $sftp) use($loop, $ssh2) {
    echo "# CONNECTED SFTP\n";

    $lines = [ "DAZZLE\n", "IS\n", "AWESOME!\n" ];
    $linesPointer = 0;

    $file = $sftp->open(__DIR__ . '/_file_write.txt', 'w+');
    $file->write();
    $file->on('drain', function(SSH2ResourceInterface $file) use(&$lines, &$linesPointer) {
        echo "# PART OF THE DATA HAS BEEN WRITTEN\n";
        if ($linesPointer < count($lines)) {
            $file->write($lines[$linesPointer++]);
        }
    });
    $file->on('finish', function(SSH2ResourceInterface $file) {
        echo "# FINISHED WRITING\n";
        $file->close();
    });
    $file->on('close', function(SSH2ResourceInterface $file) use($sftp) {
        echo "# FILE HAS BEEN CLOSED\n";
        $sftp->disconnect();
    });
});

$ssh2->on('disconnect:sftp', function(SSH2DriverInterface $sftp) use($ssh2) {
    echo "# DISCONNECTED SFTP\n";
    $ssh2->disconnect();
});

$ssh2->on('connect', function(SSH2Interface $ssh2) {
    echo "# CONNECTED\n";
    $ssh2->createDriver(SSH2::DRIVER_SFTP)
         ->connect();
});

$ssh2->on('disconnect', function(SSH2Interface $ssh2) use($loop) {
    echo "# DISCONNECTED\n";
    $loop->stop();
});

$loop->onTick(function() use($ssh2) {
    $ssh2->connect();
});

$loop->start();

Reading files

$loop   = new Loop(new SelectLoop);
$auth   = new SSH2Password($user, $pass);
$config = new SSH2Config();
$ssh2   = new SSH2($auth, $config, $loop);

$ssh2->on('connect:sftp', function(SSH2DriverInterface $sftp) use($loop, $ssh2) {
    echo "# CONNECTED SFTP\n";

    $buffer = '';
    $file = $sftp->open(__DIR__ . '/_file_read.txt', 'r+');
    $file->read();
    $file->on('data', function(SSH2ResourceInterface $file, $data) use(&$buffer) {
        $buffer .= $data;
    });
    $file->on('end', function(SSH2ResourceInterface $file) use(&$buffer) {
        echo "# FOLLOWING LINES WERE READ FROM FILE:\n";
        echo $buffer;
        $file->close();
    });
    $file->on('close', function(SSH2ResourceInterface $file) use($sftp) {
        echo "# FILE HAS BEEN CLOSED\n";
        $sftp->disconnect();
    });
});

$ssh2->on('disconnect:sftp', function(SSH2DriverInterface $sftp) use($ssh2) {
    echo "# DISCONNECTED SFTP\n";
    $ssh2->disconnect();
});

$ssh2->on('connect', function(SSH2Interface $ssh2) {
    echo "# CONNECTED\n";
    $ssh2->createDriver(SSH2::DRIVER_SFTP)
         ->connect();
});

$ssh2->on('disconnect', function(SSH2Interface $ssh2) use($loop) {
    echo "# DISCONNECTED\n";
    $loop->stop();
});

$loop->onTick(function() use($ssh2) {
    $ssh2->connect();
});

$loop->start();

See more examples in example directory., (*7)

Requirements

Dazzle SSH requires:, (*8)

  • PHP-5.6 or PHP-7.0+,
  • UNIX or Windows OS,
  • PHP SSH2 extension enabled.

Installation

To install this library make sure you have composer installed, then run following command:, (*9)

$> composer require dazzle-php/ssh

Tests

Tests can be run via:, (*10)

$> vendor/bin/phpunit -d memory_limit=1024M

Versioning

Versioning of Dazzle libraries is being shared between all packages included in Dazzle Project. That means the releases are being made concurrently for all of them. On one hand this might lead to "empty" releases for some packages at times, but don't worry. In the end it is far much easier for contributors to maintain and -- what's the most important -- much more straight-forward for users to understand the compatibility and inter-operability of the packages., (*11)

Contributing

Thank you for considering contributing to this repository!, (*12)

License

Dazzle SSH is open-sourced software licensed under the MIT license., (*13)


"Everything is possible. The impossible just takes longer." ― Dan Brown , (*14)

The Versions

23/07 2017

dev-master

9999999-dev

Dazzle Asynchronous SSH.

  Sources   Download

MIT

The Requires

 

The Development Requires

driver asynchronous ssh async ssh2 dazzle dazzle-php

25/06 2017

v0.5.0-alpha

0.5.0.0-alpha

Dazzle Asynchronous SSH.

  Sources   Download

MIT

The Requires

 

The Development Requires

driver asynchronous ssh async ssh2 dazzle dazzle-php

11/05 2017

0.4.x-dev

0.4.9999999.9999999-dev http://kraken-php.com

Kraken Asynchronous SSH.

  Sources   Download

MIT

The Requires

 

driver asynchronous ssh async ssh2 kraken kraken-php

11/05 2017

v0.4.1

0.4.1.0 http://kraken-php.com

Kraken Asynchronous SSH.

  Sources   Download

MIT

The Requires

 

driver asynchronous ssh async ssh2 kraken kraken-php

07/05 2017

v0.4.0

0.4.0.0 http://kraken-php.com

Kraken Asynchronous SSH.

  Sources   Download

MIT

The Requires

 

driver asynchronous ssh async ssh2 kraken kraken-php