From f3fbcca0c622ba5181a383863d647b9c08fd5ee0 Mon Sep 17 00:00:00 2001 From: Sergey Zhidkov Date: Thu, 20 Aug 2020 19:41:47 +0300 Subject: [PATCH 1/2] The package is designed as a component --- README.md | 29 ++++++++++------- components/FtpClient.php | 67 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 84 insertions(+), 12 deletions(-) create mode 100644 components/FtpClient.php diff --git a/README.md b/README.md index e7ab81d..66c76bf 100644 --- a/README.md +++ b/README.md @@ -32,24 +32,29 @@ to the require section of your composer.json. ## Getting Started -Connect to a server FTP : +### Configuration in config/main.php ```php -$ftp = new \yii2mod\ftp\FtpClient(); -$host = 'ftp.example.com'; -$ftp->connect($host); -$ftp->login($login, $password); + 'components' => [ + ... + 'ftp' => [ + 'class' => \yii2mod\ftp\components\FtpClient::class, + 'host' => 'ftp.site.com', + 'user' => 'root', + 'password' => '123', + 'port' => 21, + 'ssl' => true, + 'passive' => true, + 'timeout' => 90, + ], + ... + ]; ``` -OR - -Connect to a server FTP via SSL (on port 22 or other port) : +Connect to a server FTP : ```php -$ftp = new \yii2mod\ftp\FtpClient(); -$host = 'ftp.example.com'; -$ftp->connect($host, true, 22); -$ftp->login($login, $password); + $ftp = \Yii::$app->ftp->connect(); ``` Note: The connection is implicitly closed at the end of script execution (when the object is destroyed). Therefore it is unnecessary to call `$ftp->close()`, except for an explicit re-connection. diff --git a/components/FtpClient.php b/components/FtpClient.php new file mode 100644 index 0000000..9a66fce --- /dev/null +++ b/components/FtpClient.php @@ -0,0 +1,67 @@ +connect($this->host, $this->ssl, $this->port, $this->timeout); + $ftp->login($this->user, $this->password); + $ftp->pasv($this->passive); + + return $ftp; + } +} \ No newline at end of file From f1e30d0466bcd66294e38f130cbfc8e0d9750a90 Mon Sep 17 00:00:00 2001 From: Sergey Zhidkov Date: Thu, 20 Aug 2020 19:43:09 +0300 Subject: [PATCH 2/2] readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 66c76bf..dc01c0d 100644 --- a/README.md +++ b/README.md @@ -32,7 +32,7 @@ to the require section of your composer.json. ## Getting Started -### Configuration in config/main.php +Configuration in config/main.php ```php 'components' => [