Skip to content

New SCP Subsystem #66

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
vendor
*.lock
tests/bootstrap.php
tests/bootstrap.php
21 changes: 20 additions & 1 deletion README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Installation

The best way to add the library to your project is using [composer](http://getcomposer.org).

$ composer require herzult/php-ssh:~1.0
$ composer require faudin/php-ssh:~1.0

Usage
-----
Expand Down Expand Up @@ -113,6 +113,25 @@ $sftp = $session->getSftp();

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

#### Scp

You can easily access the SCP subsystem of a session using the `getScp()` method:

```php
<?php

// the session creation

$scp = $session->getScp();
$scp->send('local/path/to/file','remote/path/where/send/file');
$scp->receive('remote/path/to/file','local/path/where/save/file');

```



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

#### Publickey

The session also provides the `getPublickey()` method to access the publickey subsystem:
Expand Down
8 changes: 6 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
{
"name": "herzult/php-ssh",
"name": "faudin/php-ssh",
"type": "library",
"description": "Provides an object-oriented wrapper for the php ssh2 extension.",
"description": "Provides an object-oriented wrapper for the php ssh2 extension. (based on herzult package)",
"keywords": ["ssh", "ssh2"],
"license": "MIT",
"authors": [
{
"name": "Antoine Hérault",
"homepage": "https://github.com/Herzult"
},
{
"name": "Flavien Audin",
"homepage": "https://github.com/flavienaudin/php-ssh"
},
{
"name": "The contributors",
"homepage": "http://github.com/Herzult/php-ssh/contributors"
Expand Down
50 changes: 50 additions & 0 deletions src/Ssh/Scp.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

namespace Ssh;

use RuntimeException;

class Scp extends Subsystem
{

/**
* (PECL ssh2 &gt;= 0.9.0)<br/>
* Request a file via SCP
* @link http://php.net/manual/en/function.ssh2-scp-recv.php
*
* @param string $remote_file <p>Path to the remote file.</p>
* @param string $local_file <p>Path to the local file.</p>
* @return bool true on success or false on failure.
*/
public function receive($remote_file, $local_file)
{
return ssh2_scp_recv($this->getResource(), $remote_file, $local_file);
}

/**
* (PECL ssh2 &gt;= 0.9.0)<br/>
* Send a file via SCP
* @link http://php.net/manual/en/function.ssh2-scp-send.php
*
* @param string $local_file <p>Path to the local file.</p>
* @param string $remote_file <p>Path to the remote file.</p>
* @param int $create_mode [optional] <p>The file will be created with the mode specified by create_mode.</p>
* @return bool true on success or false on failure.
*/
public function send($local_file, $remote_file, $create_mode = 0644)
{
return ssh2_scp_send($this->getResource(), $local_file, $remote_file, $create_mode);
}

public function createResource()
{
$resource = $this->getSessionResource();

if (!is_resource($resource)) {
throw new RuntimeException('The initialization of the SCP subsystem failed.');
}

$this->resource = $resource;
}

}
13 changes: 13 additions & 0 deletions src/Ssh/Session.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,16 @@ public function getSftp()
return $this->getSubsystem('sftp');
}

/**
* Returns the Exec subsystem
*
* @return Scp
*/
public function getScp()
{
return $this->getSubsystem('scp');
}

/**
* Returns the Publickey subsystem
*
Expand Down Expand Up @@ -106,6 +116,9 @@ protected function createSubsystem($name)
case 'sftp':
$subsystem = new Sftp($this);
break;
case 'scp':
$subsystem = new Scp($this);
break;
case 'publickey':
$subsystem = new Publickey($this);
break;
Expand Down