Skip to content

Commit 6b678b7

Browse files
authored
Merge pull request #28 from lazzard/1.5
1.5
2 parents 874e1f3 + 91eff9a commit 6b678b7

File tree

14 files changed

+226
-189
lines changed

14 files changed

+226
-189
lines changed

CHANGELOG.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,18 @@
11
# Change Log
22

3+
## 1.5.3 (2021-10-10)
4+
5+
* Added new method `FtpClient::appendFile`.
6+
* Added getters and setters for various classes (see [commit](https://github.com/lazzard/php-ftp-client/commit/02df6b9be719a236701c2bcb78f990632131ffae)).
7+
* Removed the deprecated `ConnectionInterface::isSecure`.
8+
* Removed the deprecated `ConnectionInterface::isPassive`.
9+
* `FtpClient::fileSize` is now throw exception if the giving file is a directory type or an error occurs.
10+
311
## 1.5.0 (2021-10-08)
412

513
* Upgraded the code base to PHP v7.2.
614
* Upgraded PHPUnit to ^8.0.
7-
* `FtpCommand::raw` is now throw exception in failure.
15+
* `FtpCommand::raw` is now throw an exception in failure.
816
* `FtpWrapper::getErrorMessage` returns empty string instead of null if no error message is available.
917
* `FtpClient::getFeatures` throws exception in failure.
1018
* Fixed `FtpClient::createDir` for multiple directory creation.

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,8 +262,8 @@ $client->keepAlive();
262262

263263
| Version | Status | Last Release | PHP Version |
264264
|:----------:|:-------------:|:------------:|:-------------:|
265-
| 1.0.x | EOL | [v1.0.2][7] | > = 5.5 |
266-
| 1.4.x | EOL | [v1.4.2][9] | > = 5.6 |
265+
| 1.0.x | EOL | [v1.0.2][7] | >= 5.5 |
266+
| 1.4.x | EOL | [v1.4.2][9] | >= 5.6 |
267267
| 1.5.x | Latest | [v1.5.3][9] | ^7.2 \| 8.0.* |
268268

269269
[7]: https://github.com/lazzard/php-ftp-client/releases/tag/v1.0.2

TODO.md

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# TODO LIST
22

3-
This document describes some desired features, API methods, and PHP/PHPUnit upgrades for the feature releases of this library.
3+
> This document describes some desired features, API methods, and PHP/PHPUnit upgrades for the feature releases of this library.
44
55
## The next PHP Upgrades
66

@@ -12,11 +12,5 @@ This document describes some desired features, API methods, and PHP/PHPUnit upgr
1212

1313
## API methods
1414

15-
- [ ] Create a helper method for the `ftp_append` function.
16-
- [ ] Add `FtpClient::getTransferMode($file)` method to find the appropriate transfer mode (not based on file extension) for the giving **local** file.
15+
- [ ] Adding the `FtpClient::getTransferMode($file)` method to find the appropriate transfer mode (not based on file extension) for the giving **local** file.
1716
- [ ] Implement a method that allows to download all the files within the giving remote directory.
18-
19-
## Not wrapped FTP extension functions - why ?
20-
21-
- [ ] [ftp_quit](https://www.php.net/manual/en/function.ftp-quit.php) - is just an alias of [ftp_close](https://www.php.net/manual/en/function.ftp-close.php) function.
22-
- [ ] [ftp_np_put](https://www.php.net/manual/en/function.ftp-nb-put.php) - using [ftp_np_fput](https://www.php.net/manual/en/function.ftp-nb-fput.php) instead for the upload progress.

docs/FtpClient.md

Lines changed: 34 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -11,44 +11,47 @@ $client = new FtpClient(ConnectionInterface $connection);
1111

1212
```php
1313
FtpClient::allocateSpace($bytes)
14-
FtpClient::asyncDownload($remoteFile, $localFile, $callback, $resume = true, $interval = 1, $mode = FtpWrapper::BINARY)
15-
FtpClient::asyncUpload($localFile, $remoteFile, $callback, $resume = true, $interval = 1, $mode = FtpWrapper::BINARY)
14+
FtpClient::appendFile(string $remoteFile, string $content, $mode = FtpWrapper::BINARY)
15+
FtpClient::asyncDownload(string $remoteFile, string $localFile, callable $callback, bool $resume = true, int $interval = 1, int $mode = FtpWrapper::BINARY)
16+
FtpClient::asyncUpload(string $localFile, string $remoteFile, callable $callback, bool $resume = true, int $interval = 1, int $mode = FtpWrapper::BINARY)
1617
FtpClient::back()
17-
FtpClient::changeDir($directory)
18-
FtpClient::copy($remoteSource, $remoteDirectory)
19-
FtpClient::copyFromLocal($source, $destinationFolder)
20-
FtpClient::copyToLocal($remoteSource, $destinationFolder)
21-
FtpClient::createDir($directory)
22-
FtpClient::createFile($remoteFile, $content = NULL, $mode = FtpWrapper::BINARY)
23-
FtpClient::dirSize($directory)
24-
FtpClient::download($remoteFile, $localFile, $resume = true, $mode = FtpWrapper::BINARY)
25-
FtpClient::fileSize($remoteFile)
26-
FtpClient::find($pattern, $directory, $recursive = false)
18+
FtpClient::changeDir(string $directory)
19+
FtpClient::copy(string $remoteSource, string $remoteDirectory)
20+
FtpClient::copyFromLocal(string $source, string $destinationFolder)
21+
FtpClient::copyToLocal(string $remoteSource, string $destinationFolder)
22+
FtpClient::createDir(string $directory)
23+
FtpClient::createFile(string $filename, $content = NULL, int $mode = FtpWrapper::BINARY)
24+
FtpClient::dirSize(string $directory)
25+
FtpClient::download(string $remoteFile, string $localFile, bool $resume = true, int $mode = FtpWrapper::BINARY)
26+
FtpClient::fileSize(string $remoteFile)
27+
FtpClient::find(string $pattern, string $directory, bool $recursive = false)
2728
FtpClient::getConnection()
28-
FtpClient::getCount($directory, $recursive = false, $filter = self::FILE_DIR_TYPE, $ignoreDots = true)
29+
FtpClient::getCount(string $directory, bool $recursive = false, int $filter = self::FILE_DIR_TYPE, bool $ignoreDots = true)
2930
FtpClient::getCurrentDir()
30-
FtpClient::getTransferType()
3131
FtpClient::getFeatures()
32-
FtpClient::getFileContent($remoteFile)
32+
FtpClient::getFileContent(string $remoteFile, int $mode = FtpWrapper::BINARY)
3333
FtpClient::getParent()
3434
FtpClient::getSystem()
35-
FtpClient::isDir($remoteFile)
36-
FtpClient::isEmpty($remoteFile)
37-
FtpClient::isExists($remoteFile)
38-
FtpClient::isFeatureSupported($feature)
39-
FtpClient::isFile($remoteFile)
35+
FtpClient::getTransferType()
36+
FtpClient::getWrapper()
37+
FtpClient::isDir(string $remoteFile)
38+
FtpClient::isEmpty(string $remoteFile)
39+
FtpClient::isExists(string $remoteFile)
40+
FtpClient::isFeatureSupported(string $feature)
41+
FtpClient::isFile(string $remoteFile)
4042
FtpClient::keepAlive()
41-
FtpClient::lastMTime($remoteFile, $format = NULL)
42-
FtpClient::listDir($directory, $filter = self::FILE_DIR_TYPE, $ignoreDots = true)
43-
FtpClient::listDirDetails($directory, $recursive = false, $filter = self::FILE_DIR_TYPE, $ignoreDots = true)
44-
FtpClient::move($source, $destinationFolder)
45-
FtpClient::removeDir($directory)
46-
FtpClient::removeFile($remoteFile)
47-
FtpClient::rename($remoteFile, $newName)
48-
FtpClient::setCommand($command)
49-
FtpClient::setPermissions($filename, $mode)
50-
FtpClient::setWrapper($wrapper)
51-
FtpClient::upload($localFile, $remoteFile, $resume = true, $mode = FtpWrapper::BINARY)
43+
FtpClient::lastMTime(string $remoteFile, string $format = NULL)
44+
FtpClient::listDir(string $directory, int $filter = self::FILE_DIR_TYPE, bool $ignoreDots = true)
45+
FtpClient::listDirDetails(string $directory, bool $recursive = false, int $filter = self::FILE_DIR_TYPE, bool $ignoreDots = true)
46+
FtpClient::move(string $source, string $destinationFolder)
47+
FtpClient::removeDir(string $directory)
48+
FtpClient::removeFile(string $remoteFile)
49+
FtpClient::rename(string $remoteFile, string $newName)
50+
FtpClient::setCommand(FtpCommand $command)
51+
FtpClient::setConnection(ConnectionInterface $connection)
52+
FtpClient::setPermissions(string $filename, $mode)
53+
FtpClient::setWrapper(FtpWrapper $wrapper)
54+
FtpClient::upload(string $localFile, string $remoteFile, bool $resume = true, int $mode = FtpWrapper::BINARY)
5255
```
5356

5457
### Asynchronous transfer operations

src/Command/FtpCommand.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,38 @@ public function getConnection() : ConnectionInterface
4848
return $this->connection;
4949
}
5050

51+
/**
52+
* @param ConnectionInterface $connection
53+
*
54+
* @since 1.5.3
55+
*
56+
* @return void
57+
*/
58+
public function setConnection(ConnectionInterface $connection) : void
59+
{
60+
$this->connection = $connection;
61+
}
62+
5163
/**
5264
* @param FtpWrapper $wrapper
65+
*
66+
* @return void
5367
*/
5468
public function setWrapper(FtpWrapper $wrapper) : void
5569
{
5670
$this->wrapper = $wrapper;
5771
}
5872

73+
/**
74+
* @since 1.5.3
75+
*
76+
* @return FtpWrapper
77+
*/
78+
public function getWrapper() : FtpWrapper
79+
{
80+
return $this->wrapper;
81+
}
82+
5983
/**
6084
* Executes an arbitrary command on the server.
6185
*

src/Config/FtpConfig.php

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,38 @@ public function getConnection() : ConnectionInterface
4848
return $this->connection;
4949
}
5050

51+
/**
52+
* @param ConnectionInterface $connection
53+
*
54+
* @since 1.5.3
55+
*
56+
* @return void
57+
*/
58+
public function setConnection(ConnectionInterface $connection) : void
59+
{
60+
$this->connection = $connection;
61+
}
62+
5163
/**
5264
* @param FtpWrapper $wrapper
65+
*
66+
* @return void
5367
*/
5468
public function setWrapper(FtpWrapper $wrapper) : void
5569
{
5670
$this->wrapper = $wrapper;
5771
}
5872

73+
/**
74+
* @return FtpWrapper
75+
*
76+
* @since 1.5.3
77+
*/
78+
public function getWrapper() : FtpWrapper
79+
{
80+
return $this->wrapper;
81+
}
82+
5983
/**
6084
* Turn the passive mode on or off.
6185
*
@@ -72,8 +96,6 @@ public function setPassive(bool $value) : bool
7296
?: "Unable to switch FTP mode.");
7397
}
7498

75-
$this->connection->setIsPassive($value);
76-
7799
return true;
78100
}
79101

src/Connection/Connection.php

Lines changed: 14 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,9 @@ abstract class Connection implements ConnectionInterface
4343
/* @var string */
4444
protected $password;
4545

46-
/** @var bool */
47-
protected $isSecure;
48-
4946
/** @var bool */
5047
protected $isConnected;
5148

52-
/** @var bool */
53-
protected $isPassive;
54-
5549
/**
5650
* Prepares an FTP connection.
5751
*
@@ -69,20 +63,31 @@ public function __construct(string $host, string $username, string $password, in
6963
$this->password = $password;
7064
$this->port = $port;
7165
$this->timeout = $timeout;
72-
$this->isPassive = false;
7366
$this->isConnected = false;
7467

7568
$this->wrapper = new FtpWrapper($this);
7669
}
7770

7871
/**
7972
* @param FtpWrapper $wrapper
73+
*
74+
* @return void
8075
*/
8176
public function setWrapper(FtpWrapper $wrapper) : void
8277
{
8378
$this->wrapper = $wrapper;
8479
}
8580

81+
/**
82+
* @since 1.5.3
83+
*
84+
* @return FtpWrapper
85+
*/
86+
public function getWrapper() : FtpWrapper
87+
{
88+
return $this->wrapper;
89+
}
90+
8691
/**
8792
* {@inheritDoc}
8893
*
@@ -136,14 +141,6 @@ public function getPassword() : string
136141
{
137142
return $this->password;
138143
}
139-
140-
/**
141-
* @inheritDoc
142-
*/
143-
public function isSecure() : bool
144-
{
145-
return $this->isSecure;
146-
}
147144

148145
/**
149146
* @inheritDoc
@@ -153,24 +150,6 @@ public function isConnected() : bool
153150
return $this->isConnected;
154151
}
155152

156-
/**
157-
* @inheritDoc
158-
*/
159-
public function isPassive() : bool
160-
{
161-
return $this->isPassive;
162-
}
163-
164-
/**
165-
* @param bool $bool
166-
*
167-
* @return void
168-
*/
169-
public function setIsPassive(bool $bool) : void
170-
{
171-
$this->isPassive = $bool;
172-
}
173-
174153
/**
175154
* {@inheritDoc}
176155
*
@@ -202,18 +181,14 @@ public function close() : bool
202181
}
203182

204183
/**
205-
* @return bool
206-
*
207184
* @throws ConnectionException
208185
*/
209-
protected function login() : bool
186+
protected function login() : void
210187
{
211188
if (!$this->wrapper->login($this->getUsername(), $this->getPassword())) {
212189
throw new ConnectionException($this->wrapper->getErrorMessage()
213190
?: "Logging into the FTP server was failed.");
214191
}
215-
216-
return true;
217192
}
218193

219194
/**
@@ -228,10 +203,6 @@ protected function connect() : void
228203

229204
private function isValidHost($host) : bool
230205
{
231-
if (filter_var(gethostbyname($host), FILTER_VALIDATE_IP) === false) {
232-
return false;
233-
}
234-
235-
return true;
206+
return filter_var(gethostbyname($host), FILTER_VALIDATE_IP) !== false;
236207
}
237208
}

src/Connection/ConnectionInterface.php

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -63,22 +63,8 @@ public function getUsername() : string;
6363
*/
6464
public function getPassword() : string;
6565

66-
/**
67-
* @return bool
68-
*
69-
* @deprecated https://github.com/lazzard/php-ftp-client/issues/15
70-
*/
71-
public function isSecure() : bool;
72-
7366
/**
7467
* @return bool
7568
*/
7669
public function isConnected() : bool;
77-
78-
/**
79-
* @return bool
80-
*
81-
* @deprecated Deprecated and will be removed in future releases, relying on this method is discouraged.
82-
*/
83-
public function isPassive() : bool;
8470
}

src/Connection/FtpConnection.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@ protected function connect() : void
3333
?: 'FTP connection failed to remote server.');
3434
}
3535

36-
$this->isSecure = false;
37-
3836
$this->wrapper->setConnection($this);
3937
}
4038
}

0 commit comments

Comments
 (0)