|
1 |
| -# Lazzard/FtpBridge |
2 |
| - |
3 |
| -[](https://packagist.org/packages/lazzard/ftp-bridge) |
4 |
| -[](https://packagist.org/packages/lazzard/ftp-bridge) |
5 |
| -[](https://scrutinizer-ci.com/g/lazzard/ftp-bridge/?branch=master) |
6 |
| -[](https://packagist.org/packages/lazzard/ftp-bridge) |
7 |
| - |
8 |
| -A low-level implementation library of the File Transfer Protocol (FTP) in PHP that follows the RFC 959 standards and others related RFC extensions. |
9 |
| - |
10 |
| -> This library can be used to communicate with FTP servers, so you can send any FTP commands you want and receive data from the server very simply without writing the sockets/streams logic on yourself, in addition to that, the library provides a logging system to keep track of your FTP sessions. |
11 |
| -
|
12 |
| -## Requirements |
| 1 | +[](https://packagist.org/packages/lazzard/ftp-bridge) |
| 2 | +[](https://packagist.org/packages/lazzard/ftp-bridge) |
| 3 | +[](https://github.com/lazzard/ftp-bridge/actions/workflows/tests.yml) |
| 4 | +[](https://codecov.io/gh/lazzard/ftp-bridge) |
| 5 | +[](https://scrutinizer-ci.com/g/lazzard/ftp-bridge/?branch=master) |
| 6 | +[](https://packagist.org/packages/lazzard/ftp-bridge) |
13 | 7 |
|
14 |
| -* PHP version >= 5.3.0 |
15 |
| - |
16 |
| -## Installation |
17 |
| - |
18 |
| -This library is available via composer. |
| 8 | +# Lazzard/FtpBridge |
19 | 9 |
|
20 |
| -**method 1 :** |
| 10 | +Allows free communication with FTP servers according to RFC959 specification and others related RFC extensions. |
21 | 11 |
|
22 |
| -Require the exact version directly: |
| 12 | +## Getting started |
23 | 13 |
|
24 | 14 | ```console
|
25 |
| -composer require lazzard/ftp-bridge:v1.0.0-RC1 |
| 15 | +composer require lazzard/ftp-bridge:v1.0.0-RC2 |
26 | 16 | ```
|
27 | 17 |
|
28 |
| -**method 2 :** |
| 18 | +### Usage Example |
29 | 19 |
|
30 |
| - Add this two lines in your `composer.json` file : |
31 |
| - |
32 |
| -```json |
33 |
| -"minimum-stability": "dev", |
34 |
| -"prefer-stable": true |
35 |
| -``` |
36 |
| - |
37 |
| -Then require the package : |
38 |
| - |
39 |
| -```console |
40 |
| -composer require lazzard/ftp-bridge |
41 |
| -``` |
| 20 | + ```php |
| 21 | +<?php |
42 | 22 |
|
43 |
| -## Usage |
| 23 | +require __DIR__ . "/vendor/autoload.php"; |
44 | 24 |
|
45 |
| - ```php |
46 | 25 | use Lazzard\FtpBridge\Logger\ArrayLogger;
|
47 | 26 | use Lazzard\FtpBridge\Logger\LogLevel;
|
48 | 27 | use Lazzard\FtpBridge\FtpBridge;
|
49 | 28 |
|
50 |
| -require dirname(__DIR__) . "/vendor/autoload.php"; |
| 29 | +try { |
| 30 | + // Logger is optional |
| 31 | + $logger = new ArrayLogger; |
51 | 32 |
|
52 |
| -// Logger is optional |
53 |
| -$logger = new ArrayLogger(); |
| 33 | + // set log levels prefixes |
| 34 | + LogLevel::setInfo('<--'); |
| 35 | + LogLevel::setError('<--'); |
| 36 | + LogLevel::setCommand('-->'); |
54 | 37 |
|
55 |
| -// set log levels prefixes |
56 |
| -LogLevel::setInfo('<--'); |
57 |
| -LogLevel::setError('<--'); |
58 |
| -LogLevel::setCommand('-->'); |
| 38 | + // create bridge instance |
| 39 | + $ftp = new FtpBridge($logger); |
59 | 40 |
|
60 |
| -// create bridge instance |
61 |
| -$ftp = new FtpBridge($logger); |
| 41 | + |
| 42 | + $username = 'username'; |
| 43 | + $password = 'password'; |
62 | 44 |
|
63 |
| - |
64 |
| -$username = 'username'; |
65 |
| -$password = 'password'; |
| 45 | + if ($ftp->connect($hostname, 21)) { |
| 46 | + // connected |
| 47 | + if ($ftp->login($username, $password)) { |
| 48 | + // logged |
66 | 49 |
|
67 |
| -if ($ftp->connect($hostname, 21)) { |
68 |
| - // connected |
69 |
| - if ($ftp->login($username, $password)) { |
70 |
| - // logged |
| 50 | + $ftp->send("PWD"); |
| 51 | + $ftp->receive(); |
71 | 52 |
|
72 |
| - $ftp->send("PWD"); |
73 |
| - $ftp->receive(); |
| 53 | + // open a passive data connection |
| 54 | + if ($ftp->openPassive()) { |
| 55 | + $ftp->send("NLST ."); |
| 56 | + $ftp->receive(); |
74 | 57 |
|
75 |
| - // open a passive data connection |
76 |
| - if ($ftp->openPassive()) { |
77 |
| - $ftp->send("NLST ."); |
78 |
| - $ftp->receive(); |
79 |
| - |
80 |
| - $ftp->receiveData(); |
81 |
| - $ftp->receive(); |
| 58 | + $ftp->receiveData(); |
| 59 | + $ftp->receive(); |
| 60 | + } |
82 | 61 | }
|
| 62 | + |
| 63 | + $ftp->send("QUIT"); |
| 64 | + $ftp->receive(); |
83 | 65 | }
|
84 | 66 |
|
85 |
| - $ftp->send("QUIT"); |
86 |
| - $ftp->receive(); |
| 67 | + print_r($logger->getLogs()); |
| 68 | + |
| 69 | +} catch (Exception $ex) { |
| 70 | + print_r($ex->getMessage(); |
87 | 71 | }
|
88 |
| - |
89 |
| -print_r($logger->getLogs()); |
90 | 72 | ```
|
91 | 73 |
|
92 |
| -**Result :** |
| 74 | +**Result :** |
93 | 75 |
|
94 | 76 | ```
|
95 | 77 | Array
|
@@ -137,4 +119,4 @@ lazzard.org
|
137 | 119 | 221 Logout.
|
138 | 120 |
|
139 | 121 | )
|
140 |
| -``` |
| 122 | +``` |
0 commit comments