FTP client
Definition at line 15 of file Ftp.php.
◆ _tmpFilename()
_tmpFilename |
( |
|
$new = false | ) |
|
|
protected |
- Parameters
-
- Returns
- string
Definition at line 330 of file Ftp.php.
333 $this->
_tmpFilename = tempnam(md5(uniqid(rand(),
true)),
'');
◆ cd()
Change current working directory
- Parameters
-
- Returns
- bool @SuppressWarnings(PHPMD.ShortMethodName)
Implements IoInterface.
Definition at line 199 of file Ftp.php.
201 return @ftp_chdir($this->_conn, $dir);
◆ chmod()
chmod |
( |
|
$filename, |
|
|
|
$mode |
|
) |
| |
Change mode of a directory or a file
- Parameters
-
- Returns
- bool
Implements IoInterface.
Definition at line 303 of file Ftp.php.
305 return @ftp_chmod($this->_conn,
$mode, $filename);
if($exist=($block->getProductCollection() && $block->getProductCollection() ->getSize())) $mode
◆ close()
Close a connection
- Returns
- bool
Implements IoInterface.
Definition at line 149 of file Ftp.php.
151 return @ftp_close($this->_conn);
◆ ls()
- Parameters
-
null | $grep | ignored parameter |
- Returns
- array @SuppressWarnings(PHPMD.ShortMethodName) @SuppressWarnings(PHPMD.UnusedFormalParameter)
Implements IoInterface.
Definition at line 314 of file Ftp.php.
316 $ls = @ftp_nlist($this->_conn,
'.');
319 foreach ($ls as $file) {
320 $list[] = [
'text' => $file,
'id' => $this->
pwd() .
'/' . $file];
◆ mkdir()
mkdir |
( |
|
$dir, |
|
|
|
$mode = 0777 , |
|
|
|
$recursive = true |
|
) |
| |
Create a directory
- Todo:
- implement $mode and $recursive
- Parameters
-
string | $dir | |
int | $mode | |
bool | $recursive | |
- Returns
- bool @SuppressWarnings(PHPMD.UnusedFormalParameter)
Implements IoInterface.
Definition at line 164 of file Ftp.php.
166 return @ftp_mkdir($this->_conn, $dir);
◆ mv()
Rename or move a directory or a file
- Parameters
-
- Returns
- bool @SuppressWarnings(PHPMD.ShortMethodName)
Implements IoInterface.
Definition at line 291 of file Ftp.php.
293 return @ftp_rename($this->_conn, $src, $dest);
◆ open()
Open a connection
Possible argument keys:
- host required
- port default 21
- timeout default 90
- user default anonymous
- password default empty
- ssl default false
- passive default false
- path default empty
- file_mode default FTP_BINARY
- Parameters
-
- Returns
- true
- Exceptions
-
LocalizedException | @SuppressWarnings(PHPMD.CyclomaticComplexity) @SuppressWarnings(PHPMD.NPathComplexity) |
Implements IoInterface.
Definition at line 77 of file Ftp.php.
79 if (empty($args[
'host'])) {
81 throw new LocalizedException(
new Phrase(
'The specified host is empty. Set the host and try again.'));
84 if (empty($args[
'port'])) {
88 if (empty($args[
'user'])) {
89 $args[
'user'] =
'anonymous';
93 if (empty($args[
'password'])) {
94 $args[
'password'] =
'';
97 if (empty($args[
'timeout'])) {
98 $args[
'timeout'] = 90;
101 if (empty($args[
'file_mode'])) {
102 $args[
'file_mode'] = FTP_BINARY;
105 $this->_config = $args;
107 if (empty($this->_config[
'ssl'])) {
108 $this->_conn = @ftp_connect($this->_config[
'host'], $this->_config[
'port'], $this->_config[
'timeout']);
110 $this->_conn = @ftp_ssl_connect($this->_config[
'host'], $this->_config[
'port'], $this->_config[
'timeout']);
114 throw new LocalizedException(
115 new Phrase(
"The FTP connection couldn't be established because of an invalid host or port.")
119 if (!@ftp_login($this->_conn, $this->_config[
'user'], $this->_config[
'password'])) {
122 throw new LocalizedException(
new Phrase(
'The username or password is invalid. Verify both and try again.'));
125 if (!empty($this->_config[
'path'])) {
126 if (!@ftp_chdir($this->_conn, $this->_config[
'path'])) {
129 throw new LocalizedException(
new Phrase(
'The path is invalid. Verify and try again.'));
133 if (!empty($this->_config[
'passive'])) {
134 if (!@ftp_pasv($this->_conn,
true)) {
137 throw new LocalizedException(
new Phrase(
'The file transfer mode is invalid. Verify and try again.'));
const ERROR_INVALID_CONNECTION
const ERROR_INVALID_LOGIN
◆ pwd()
Get current working directory
- Returns
- string
Implements IoInterface.
Definition at line 187 of file Ftp.php.
189 return @ftp_pwd($this->_conn);
◆ read()
read |
( |
|
$filename, |
|
|
|
$dest = null |
|
) |
| |
Read a file to result, file or stream
- Parameters
-
string | $filename | |
string | resource | null | $dest | destination file name, stream, or if null will return file contents |
- Returns
- false|string
Implements IoInterface.
Definition at line 211 of file Ftp.php.
213 if (is_string($dest)) {
214 $result = ftp_get($this->_conn, $dest, $filename, $this->_config[
'file_mode']);
218 }
elseif ($dest ===
null) {
225 $result = ftp_fget($this->_conn, $stream, $filename, $this->_config[
'file_mode']);
227 if ($dest ===
null) {
elseif(isset( $params[ 'redirect_parent']))
const ERROR_INVALID_DESTINATION
◆ rm()
Delete a file
- Parameters
-
- Returns
- bool @SuppressWarnings(PHPMD.ShortMethodName)
Implements IoInterface.
Definition at line 278 of file Ftp.php.
280 return @ftp_delete($this->_conn, $filename);
◆ rmdir()
rmdir |
( |
|
$dir, |
|
|
|
$recursive = false |
|
) |
| |
Delete a directory
- Parameters
-
string | $dir | |
bool | $recursive | |
- Returns
- bool @SuppressWarnings(PHPMD.UnusedFormalParameter)
Implements IoInterface.
Definition at line 177 of file Ftp.php.
179 return @ftp_rmdir($this->_conn, $dir);
◆ write()
write |
( |
|
$filename, |
|
|
|
$src, |
|
|
|
$mode = null |
|
) |
| |
Write a file from string, file or stream
- Parameters
-
string | $filename | |
string | resource | $src | filename, string data or source stream |
null | $mode | |
- Returns
- bool @SuppressWarnings(PHPMD.UnusedFormalParameter)
Implements IoInterface.
Definition at line 247 of file Ftp.php.
250 return @ftp_put($this->_conn, $filename, $src, $this->_config[
'file_mode']);
252 if (is_string($src)) {
254 fputs($stream, $src);
263 $result = ftp_fput($this->_conn, $filename, $stream, $this->_config[
'file_mode']);
264 if (is_string($src)) {
elseif(isset( $params[ 'redirect_parent']))
const ERROR_INVALID_SOURCE
◆ $_config
◆ $_conn
◆ $_error
◆ $_tmpFilename
◆ ERROR_EMPTY_HOST
const ERROR_EMPTY_HOST = 1 |
◆ ERROR_INVALID_CONNECTION
const ERROR_INVALID_CONNECTION = 2 |
◆ ERROR_INVALID_DESTINATION
const ERROR_INVALID_DESTINATION = 6 |
◆ ERROR_INVALID_LOGIN
const ERROR_INVALID_LOGIN = 3 |
◆ ERROR_INVALID_MODE
const ERROR_INVALID_MODE = 5 |
◆ ERROR_INVALID_PATH
const ERROR_INVALID_PATH = 4 |
◆ ERROR_INVALID_SOURCE
const ERROR_INVALID_SOURCE = 7 |
The documentation for this class was generated from the following file:
- vendor/magento/framework/Filesystem/Io/Ftp.php