PHP Class elFinderVolumeFTP

Author: Dmitry (dio) Levashov
Author: Cem (discofever)
Inheritance: extends elFinderVolumeDriver
显示文件 Open project: studio-42/elfinder Class Usage Examples

Protected Properties

Property Type Description
$connect ftp FTP Connection Instance
$driverId string Driver id Must be started from letter and contains [a-z0-9] Used as part of volume id
$ftpError string Last FTP error message
$ftpOsUnix boolean FTP server output list as ftp on linux
$tmp string Tmp folder path
$tmpPath string Directory for tmp files If not set driver will try to use tmbDir as tmpDir

Public Methods

Method Description
__construct ( ) Constructor Extend options with required fields
netmountPrepare ( $options ) : Array Prepare Call from elFinder::netmout() before volume->mount()
umount ( ) : void Close opened connection

Protected Methods

Method Description
_abspath ( string $path ) : string Convert path related to root dir into real path
_archive ( string $dir, array $files, string $name, array $arc ) : string | boolean Create archive and return its path
_basename ( string $path ) : string Return file name
_checkArchivers ( ) : void Detect available archivers
_chmod ( string $path, string $mode ) : boolean chmod availability
_copy ( string $source, string $targetDir, string $name ) : boolean Copy file into another file
_dimensions ( string $path, string $mime ) : string | false Return object width and height Ususaly used for images, but can be realize for video etc.
_dirname ( string $path ) : string Return parent directory path
_extract ( string $path, array $arc ) : true Extract files from archive
_fclose ( resource $fp, string $path = '' ) : boolean Close opened file
_filePutContents ( string $path, string $content ) : boolean Write a string to a file
_findSymlinks ( string $path ) : boolean Recursive symlinks search
_fopen ( string $path, string $mode = 'rb' ) : false | resource Open file and return file pointer
_getContents ( string $path ) : string | false Get file contents
_inpath ( string $path, string $parent ) : boolean Return true if $path is children of $parent
_joinPath ( string $dir, string $name ) : string Join dir name and file name and retur full path
_mkdir ( string $path, string $name ) : string | boolean Create dir and return created dir path or false on failed
_mkfile ( string $path, string $name ) : string | boolean Create file and return it's path or false on failed
_move ( string $source, $targetDir, string $name ) : boolean | string Move file into another parent dir.
_normpath ( string $path ) : string Return normalized path, this works the same as os.path.normpath() in Python
_path ( string $path ) : string Return fake path started from root dir
_relpath ( string $path ) : string Return file path related to root dir
_rmdir ( string $path ) : boolean Remove dir
_save ( resource $fp, string $dir, string $name, array $stat ) : boolean | string Create new file and write into it from file pointer.
_scandir ( string $path ) : array Return files list in directory.
_stat ( string $path ) : array | false Return stat for given path.
_subdirs ( string $path ) : boolean Return true if path is dir and has at least one childs directory
_symlink ( string $target, string $path, string $name ) : boolean Create symlink. FTP driver does not support symlinks.
_unlink ( string $path ) : boolean Remove file
cacheDir ( string $path ) : void Cache dir contents
configure ( ) : void Configure after successfull mount.
connect ( ) : boolean Connect to ftp server
ftpMode ( string $path ) : string Return ftp transfer mode for file
ftp_scan_dir ( $remote_directory, $targets = null ) : array Gets an array of absolute remote FTP paths of files and folders in $remote_directory omitting symbolic links.
init ( ) : boolean Prepare FTP connection Connect to remote server and check if credentials are correct, if so, store the connection id in $ftp_conn
normalizeRawWindows ( string $raw ) : array Normalize MS-DOS style FTP LIST Raw line
parsePermissions ( string $perm, string $user = '' ) : string Parse permissions string. Return array(read => true/false, write => true/false)
parseRaw ( string $raw, $base, boolean $nameOnly = false ) : array Parse line from ftp_rawlist() output and return file stat (array)

Private Methods

Method Description
deleteDir ( $dirPath ) : boolean Delete local directory recursively.
ftp_download_files ( $remote_directory, array $files, $dest_local_directory ) : boolean Downloads specified files from remote directory if there is a directory among files it is downloaded recursively (omitting symbolic links).
listFilesInDirectory ( $dir, $omitSymlinks, string $prefix = '' ) : array Returns array of strings containing all files and folders in the specified local directory.
tempDir ( ) : string Create writable temporary directory and return path to it.

Method Details

__construct() public method

Constructor Extend options with required fields
Author: Dmitry (dio) Levashov
Author: Cem (DiscoFever)
public __construct ( )

_abspath() protected method

Convert path related to root dir into real path
Author: Dmitry (dio) Levashov
protected _abspath ( string $path ) : string
$path string file path
return string

_archive() protected method

Create archive and return its path
Author: Dmitry (dio) Levashov,
Author: Alexey Sukhotin
protected _archive ( string $dir, array $files, string $name, array $arc ) : string | boolean
$dir string target dir
$files array files names list
$name string archive name
$arc array archiver options
return string | boolean

_basename() protected method

Return file name
Author: Naoki Sawada
protected _basename ( string $path ) : string
$path string file path
return string

_checkArchivers() protected method

Detect available archivers
protected _checkArchivers ( ) : void
return void

_chmod() protected method

chmod availability
protected _chmod ( string $path, string $mode ) : boolean
$path string
$mode string
return boolean

_copy() protected method

Copy file into another file
Author: Dmitry (dio) Levashov
protected _copy ( string $source, string $targetDir, string $name ) : boolean
$source string source file path
$targetDir string target directory path
$name string new file name
return boolean

_dimensions() protected method

..
Author: Dmitry (dio) Levashov
protected _dimensions ( string $path, string $mime ) : string | false
$path string file path
$mime string file mime type
return string | false

_dirname() protected method

Return parent directory path
Author: Naoki Sawada
protected _dirname ( string $path ) : string
$path string file path
return string

_extract() protected method

Extract files from archive
Author: Dmitry (dio) Levashov,
Author: Alexey Sukhotin
protected _extract ( string $path, array $arc ) : true
$path string archive path
$arc array archiver command and arguments (same as in $this->archivers)
return true

_fclose() protected method

Close opened file
Author: Dmitry (dio) Levashov
protected _fclose ( resource $fp, string $path = '' ) : boolean
$fp resource file pointer
$path string
return boolean

_filePutContents() protected method

Write a string to a file
Author: Dmitry (dio) Levashov
protected _filePutContents ( string $path, string $content ) : boolean
$path string file path
$content string new file content
return boolean

_fopen() protected method

Open file and return file pointer
Author: Dmitry (dio) Levashov
protected _fopen ( string $path, string $mode = 'rb' ) : false | resource
$path string file path
$mode string
return false | resource

_getContents() protected method

Get file contents
Author: Dmitry (dio) Levashov
protected _getContents ( string $path ) : string | false
$path string file path
return string | false

_inpath() protected method

Return true if $path is children of $parent
Author: Dmitry (dio) Levashov
protected _inpath ( string $path, string $parent ) : boolean
$path string path to check
$parent string parent path
return boolean

_joinPath() protected method

Join dir name and file name and retur full path
Author: Dmitry (dio) Levashov
protected _joinPath ( string $dir, string $name ) : string
$dir string
$name string
return string

_mkdir() protected method

Create dir and return created dir path or false on failed
Author: Dmitry (dio) Levashov
protected _mkdir ( string $path, string $name ) : string | boolean
$path string parent dir path
$name string new directory name
return string | boolean

_mkfile() protected method

Create file and return it's path or false on failed
Author: Dmitry (dio) Levashov
protected _mkfile ( string $path, string $name ) : string | boolean
$path string parent dir path
$name string new file name
return string | boolean

_move() protected method

Return new file path or false.
Author: Dmitry (dio) Levashov
protected _move ( string $source, $targetDir, string $name ) : boolean | string
$source string source file path
$targetDir
$name string file name
return boolean | string

_normpath() protected method

Return normalized path, this works the same as os.path.normpath() in Python
Author: Troex Nevelin
protected _normpath ( string $path ) : string
$path string path
return string

_path() protected method

Return fake path started from root dir
Author: Dmitry (dio) Levashov
protected _path ( string $path ) : string
$path string file path
return string

_relpath() protected method

Return file path related to root dir
Author: Dmitry (dio) Levashov
protected _relpath ( string $path ) : string
$path string file path
return string

_rmdir() protected method

Remove dir
Author: Dmitry (dio) Levashov
protected _rmdir ( string $path ) : boolean
$path string dir path
return boolean

_save() protected method

Return new file path or false on error.
Author: Dmitry (dio) Levashov
protected _save ( resource $fp, string $dir, string $name, array $stat ) : boolean | string
$fp resource file pointer
$dir string target dir path
$name string file name
$stat array file stat (required by some virtual fs)
return boolean | string

_scandir() protected method

Return files list in directory.
Author: Dmitry (dio) Levashov
Author: Cem (DiscoFever)
protected _scandir ( string $path ) : array
$path string dir path
return array

_stat() protected method

Stat contains following fields: - (int) size file size in b. required - (int) ts file modification time in unix time. required - (string) mime mimetype. required for folders, others - optionally - (bool) read read permissions. required - (bool) write write permissions. required - (bool) locked is object locked. optionally - (bool) hidden is object hidden. optionally - (string) alias for symlinks - link target path relative to root path. optionally - (string) target for symlinks - link target path. optionally If file does not exists - returns empty array or false.
Author: Dmitry (dio) Levashov
protected _stat ( string $path ) : array | false
$path string file path
return array | false

_subdirs() protected method

Return true if path is dir and has at least one childs directory
Author: Dmitry (dio) Levashov
protected _subdirs ( string $path ) : boolean
$path string dir path
return boolean

cacheDir() protected method

Cache dir contents
Author: Dmitry Levashov
protected cacheDir ( string $path ) : void
$path string dir path
return void

configure() protected method

Configure after successfull mount.
Author: Dmitry (dio) Levashov
protected configure ( ) : void
return void

connect() protected method

Connect to ftp server
Author: Dmitry (dio) Levashov
protected connect ( ) : boolean
return boolean

ftpMode() protected method

Return ftp transfer mode for file
Author: Dmitry (dio) Levashov
protected ftpMode ( string $path ) : string
$path string file path
return string

ftp_scan_dir() protected method

Gets an array of absolute remote FTP paths of files and folders in $remote_directory omitting symbolic links.
protected ftp_scan_dir ( $remote_directory, $targets = null ) : array
$remote_directory string remote FTP path to scan for file and folders recursively
$targets array Array of target item. `null` is to get all of items
return array of elements each of which is an array of two elements:
  • $item['path'] - absolute remote FTP path
  • $item['type'] - either 'f' for file or 'd' for directory

init() protected method

Prepare FTP connection Connect to remote server and check if credentials are correct, if so, store the connection id in $ftp_conn
Author: Dmitry (dio) Levashov
Author: Cem (DiscoFever)
protected init ( ) : boolean
return boolean

netmountPrepare() public method

Prepare Call from elFinder::netmout() before volume->mount()
Author: Naoki Sawada
public netmountPrepare ( $options ) : Array
$options
return Array

normalizeRawWindows() protected method

Normalize MS-DOS style FTP LIST Raw line
Author: Naoki Sawada
protected normalizeRawWindows ( string $raw ) : array
$raw string line from FTP LIST (MS-DOS style)
return array

parsePermissions() protected method

Parse permissions string. Return array(read => true/false, write => true/false)
Author: Dmitry (dio) Levashov
protected parsePermissions ( string $perm, string $user = '' ) : string
$perm string permissions string
$user string
return string

parseRaw() protected method

Parse line from ftp_rawlist() output and return file stat (array)
Author: Dmitry Levashov
protected parseRaw ( string $raw, $base, boolean $nameOnly = false ) : array
$raw string line from ftp_rawlist() output
$base
$nameOnly boolean
return array

umount() public method

Close opened connection
Author: Dmitry (dio) Levashov
public umount ( ) : void
return void

Property Details

$connect protected_oe property

FTP Connection Instance
protected ftp $connect
return ftp

$driverId protected_oe property

Driver id Must be started from letter and contains [a-z0-9] Used as part of volume id
protected string $driverId
return string

$ftpError protected_oe property

Last FTP error message
protected string $ftpError
return string

$ftpOsUnix protected_oe property

FTP server output list as ftp on linux
protected bool $ftpOsUnix
return boolean

$tmp protected_oe property

Tmp folder path
protected string $tmp
return string

$tmpPath protected_oe property

Directory for tmp files If not set driver will try to use tmbDir as tmpDir
protected string $tmpPath
return string