diff --git a/.gitignore b/.gitignore index f69293a..b8592b4 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,3 @@ vendor *.lock -tests/bootstrap.php \ No newline at end of file +tests/bootstrap.php diff --git a/README.markdown b/README.markdown index c6e0824..f2a145d 100644 --- a/README.markdown +++ b/README.markdown @@ -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 ----- @@ -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 +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: diff --git a/composer.json b/composer.json index 9a65402..0d6bf67 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { - "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": [ @@ -9,6 +9,10 @@ "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" diff --git a/src/Ssh/Scp.php b/src/Ssh/Scp.php new file mode 100644 index 0000000..4f50b49 --- /dev/null +++ b/src/Ssh/Scp.php @@ -0,0 +1,50 @@ + + * Request a file via SCP + * @link http://php.net/manual/en/function.ssh2-scp-recv.php + * + * @param string $remote_file
Path to the remote file.
+ * @param string $local_filePath to the local file.
+ * @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 >= 0.9.0)Path to the local file.
+ * @param string $remote_filePath to the remote file.
+ * @param int $create_mode [optional]The file will be created with the mode specified by create_mode.
+ * @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; + } + +} \ No newline at end of file diff --git a/src/Ssh/Session.php b/src/Ssh/Session.php index 4bf30a9..ebbfcdd 100644 --- a/src/Ssh/Session.php +++ b/src/Ssh/Session.php @@ -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 * @@ -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;