Skip to content

Commit 98593ad

Browse files
committed
Updated service namings and docuentation
1 parent 70f03a7 commit 98593ad

File tree

5 files changed

+55
-22
lines changed

5 files changed

+55
-22
lines changed

README.md

+16-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ Symfony2 Helpers - SFTP bundle
55

66
This bundle provide simple interface for transfer files by [SFTP](https://en.wikipedia.org/wiki/SFTP) protocol.
77

8-
Installation:
8+
Installation
9+
==============
910

1011
1) Install libssh2-php library:
1112

@@ -35,5 +36,18 @@ Installation:
3536
// ... other code
3637
}
3738
```
39+
Usage
40+
=======
3841
39-
4) Use service `sftp` for transfering files by SFTP. Details about service usage see here.
42+
1) Use service `sf2h.sftp` to transfer files over SFTP:
43+
44+
```php
45+
$this->get('sf2h.sftp')->copy('/path/to/remoteFile', '/path/to/localFile');
46+
// or
47+
$this->get('sf2h.sftp')->send('/path/to/localFile', '/path/to/remoteFile');
48+
```
49+
50+
2) From CLI could be used one of the following commands:
51+
52+
- `php app(bin)/console sftp:copy` - to copy files from remote server to local machine
53+
- `php app(bin)/console sftp:send` - to copy files from local server to remote machine

Resources/config/services.xml

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
66

77
<parameters>
8-
<parameter key="sftp.class">SF2Helpers\SFTPBundle\SFTP\SFTP</parameter>
8+
<parameter key="sf2h.sftp.class">SF2Helpers\SFTPBundle\SFTP\SFTP</parameter>
99
</parameters>
1010

1111
<services>
12-
<service id="sftp" class="%sftp.class%" />
12+
<service id="sf2h.sftp" class="%sf2h.sftp.class%" />
1313
</services>
1414

1515
</container>

SFTP/ConnectionInterface.php

+16-1
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,27 @@
55
interface ConnectionInterface
66
{
77
/**
8+
* Establish connection with remote host via username and password
9+
*
810
* @param $host
911
* @param $username
1012
* @param $password
11-
* @return mixed
1213
*/
1314
public function connect($host, $username, $password);
1415

16+
/**
17+
* Establish connection with remote host via public and private keys
18+
*
19+
* @param $host
20+
* @param $username
21+
* @param $pubkeyfile
22+
* @param $privkeyfile
23+
* @param null $passphrase
24+
*/
25+
public function connectWithKey($host, $username, $pubkeyfile, $privkeyfile, $passphrase = null);
26+
27+
/**
28+
* Implementation of this function should close established connection
29+
*/
1530
public function disconnect();
1631
}

SFTP/ResourceTransferInterface.php

+12
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,28 @@
55
interface ResourceTransferInterface
66
{
77
/**
8+
* Copy remote file to local machine
9+
*
810
* @param $remoteFile
911
* @param $localFile
1012
* @return mixed
1113
*/
1214
public function copy($remoteFile, $localFile);
1315

1416
/**
17+
* Copy file from local machine to remote
18+
*
1519
* @param $localFile
1620
* @param $remoteFile
1721
* @return mixed
1822
*/
1923
public function send($localFile, $remoteFile);
24+
25+
/**
26+
* Return array of files names from remote dir
27+
*
28+
* @param $remoteDir
29+
* @return array
30+
*/
31+
public function getRemoteFilesList($remoteDir);
2032
}

SFTP/SFTP.php

+9-17
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,7 @@ class SFTP implements ConnectionInterface, ResourceTransferInterface
1919
private $sftp;
2020

2121
/**
22-
* @param string $host
23-
* @param string $username
24-
* @param string|null $password
22+
* @inheritdoc
2523
*/
2624
public function connect($host, $username, $password = null)
2725
{
@@ -34,11 +32,7 @@ public function connect($host, $username, $password = null)
3432
}
3533

3634
/**
37-
* @param string $host
38-
* @param string $username
39-
* @param string $pubkeyfile
40-
* @param string $privkeyfile
41-
* @param string|null $passphrase
35+
* @inheritdoc
4236
*/
4337
public function connectWithKey($host, $username, $pubkeyfile, $privkeyfile, $passphrase = null)
4438
{
@@ -51,9 +45,7 @@ public function connectWithKey($host, $username, $pubkeyfile, $privkeyfile, $pas
5145
}
5246

5347
/**
54-
* @param $remoteFile
55-
* @param $localFile
56-
* @throws \Exception
48+
* @inheritdoc
5749
*/
5850
public function copy($remoteFile, $localFile)
5951
{
@@ -66,9 +58,7 @@ public function copy($remoteFile, $localFile)
6658
}
6759

6860
/**
69-
* @param $localFile
70-
* @param $remoteFile
71-
* @throws \Exception
61+
* @inheritdoc
7262
*/
7363
public function send($localFile, $remoteFile)
7464
{
@@ -80,10 +70,9 @@ public function send($localFile, $remoteFile)
8070
}
8171

8272
/**
83-
* @param $dir
84-
* @return array
73+
* @inheritdoc
8574
*/
86-
public function getFilesList($dir)
75+
public function getRemoteFilesList($dir)
8776
{
8877
$handle = opendir("ssh2.sftp://$this->sftp" . $dir);
8978
$files = [];
@@ -95,6 +84,9 @@ public function getFilesList($dir)
9584
return $files;
9685
}
9786

87+
/**
88+
* @inheritdoc
89+
*/
9890
public function disconnect()
9991
{
10092
ssh2_exec($this->connection, 'exit');

0 commit comments

Comments
 (0)