diff --git a/README.md b/README.md index e7ab81d..dc01c0d 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