PHP Class phpseclib\Net\SFTP

Author: Jim Wigginton ([email protected])
Inheritance: extends SSH2
Afficher le fichier Open project: phpseclib/phpseclib Class Usage Examples

Méthodes publiques

Свойство Type Description
$extensions array Extensions supported by the server
$max_sftp_packet array Max SFTP Packet Size
$packet_buffer string Packet Buffer
$packet_log array Packet Log
$packet_type integer The request ID exists in the off chance that a packet is sent out-of-order. Of course, this library doesn't support concurrent actions, so it's somewhat academic, here.
$packet_type_log array Packet Type Log
$packet_types array Packet Types
$pwd string Current working directory
$request_id integer The request ID exists in the off chance that a packet is sent out-of-order. Of course, this library doesn't support concurrent actions, so it's somewhat academic, here.
$sftp_errors string Error information
$sortOptions array Sort Options
$stat_cache array Rather than always having to open a directory and close it immediately there after to see if a file is a directory we'll cache the results.
$status_codes array Status Codes
$use_stat_cache boolean Stat Cache Flag
$version integer Server SFTP version

Méthodes publiques

Méthode Description
__construct ( string $host, integer $port = 22, integer $timeout = 10 ) : SFTP Default Constructor.
_close_handle ( string $handle ) : boolean Close handle
_comparator ( array $a, array $b ) : integer Compares two rawlist entries using parameters set by setListOrder()
_delete_recursive ( string $path, integer &$i ) : boolean Recursively deletes directories on the SFTP server
_disconnect ( integer $reason ) : boolean Disconnect
_get_lstat_cache_prop ( string $path, string $prop ) : mixed Return an lstat properity
_get_sftp_packet ( ) : string Receives SFTP Packets
_get_stat_cache_prop ( string $path, string $prop ) : mixed Return a stat properity
_get_xstat_cache_prop ( string $path, string $prop, $type ) : mixed Return a stat or lstat properity
_list ( string $dir, boolean $raw = true ) : mixed Reads a list, be it detailed or not, of files in the given directory
_logError ( string $response, integer $status ) Logs errors
_mkdir_helper ( string $dir, $attr ) : boolean Helper function for directory creation
_nlist_helper ( string $dir, boolean $recursive, string $relativeDir ) : mixed Helper method for nlist
_parseAttributes ( string &$response ) : array Parse Attributes
_parseLongname ( string $longname ) : mixed Parse Longname
_parseMode ( integer $mode ) : integer Attempt to identify the file type
_query_stat_cache ( $path ) : mixed Checks cache for path
_read_put_responses ( integer $i ) : boolean Reads multiple successive SSH_FXP_WRITE responses
_realpath ( string $path ) : mixed Canonicalize the Server-Side Path Name
_remove_from_stat_cache ( string $path ) : boolean Remove files / directories from cache
_send_sftp_packet ( integer $type, string $data ) : boolean Sends SFTP Packets
_setstat ( string $filename, string $attr, boolean $recursive ) : boolean Sets information about a file
_setstat_recursive ( string $path, string $attr, integer &$i ) : boolean Recursively sets information on directories on the SFTP server
_stat ( string $filename, integer $type ) : mixed Returns general information about a file or symbolic link
_update_stat_cache ( string $path, mixed $value ) Save files / directories to cache
chdir ( string $dir ) : boolean Changes the current directory
chgrp ( string $filename, integer $gid, boolean $recursive = false ) : boolean Changes file or directory group
chmod ( integer $mode, string $filename, boolean $recursive = false ) : mixed Set permissions on a file.
chown ( string $filename, integer $uid, boolean $recursive = false ) : boolean Changes file or directory owner
clearStatCache ( ) Clear the stat cache
delete ( string $path, boolean $recursive = true ) : boolean Deletes a file on the SFTP server.
disableStatCache ( ) Disable the stat cache
enableStatCache ( ) Enable the stat cache
file_exists ( string $path ) : boolean Checks whether a file or directory exists
fileatime ( string $path ) : mixed Gets last access time of file
filegroup ( string $path ) : mixed Gets file group
filemtime ( string $path ) : mixed Gets file modification time
fileowner ( string $path ) : mixed Gets file owner
fileperms ( string $path ) : mixed Gets file permissions
filesize ( string $path ) : mixed Gets file size
filetype ( string $path ) : mixed Gets file type
get ( string $remote_file, string $local_file = false, integer $offset, integer $length ) : mixed Downloads a file from the SFTP server.
getLastSFTPError ( ) : string Returns the last error
getSFTPErrors ( ) : string Returns all errors
getSFTPLog ( ) : string Returns a log of the packets that have been sent and received.
getSupportedVersions ( ) : array Get supported SFTP versions
is_dir ( string $path ) : boolean Tells whether the filename is a directory
is_file ( string $path ) : boolean Tells whether the filename is a regular file
is_link ( string $path ) : boolean Tells whether the filename is a symbolic link
is_readable ( string $path ) : boolean Tells whether a file exists and is readable
is_writable ( string $path ) : boolean Tells whether the filename is writable
is_writeable ( string $path ) : boolean Tells whether the filename is writeable
login ( string $username ) : boolean Login
lstat ( string $filename ) : mixed Returns general information about a file or symbolic link.
mkdir ( string $dir, $mode, $recursive = false ) : boolean Creates a directory.
nlist ( string $dir = '.', boolean $recursive = false ) : mixed Returns a list of files in the given directory
put ( string $remote_file, string | resource $data, integer $mode = self::SOURCE_STRING, integer $start, integer $local_start, callable | null $progressCallback = null ) : boolean Uploads a file to the SFTP server.
pwd ( ) : mixed Returns the current directory name
rawlist ( string $dir = '.', boolean $recursive = false ) : mixed Returns a detailed list of files in the given directory
readlink ( string $link ) : mixed Return the target of a symbolic link
realpath ( string $path ) : mixed Returns canonicalized absolute pathname
rename ( string $oldname, string $newname ) : boolean Renames a file or a directory on the SFTP server
rmdir ( string $dir ) : boolean Removes a directory.
setListOrder ( ) Defines how nlist() and rawlist() will be sorted - if at all.
size ( string $filename ) : mixed Returns the file size, in bytes, or false, on failure
stat ( string $filename ) : mixed Returns general information about a file.
symlink ( string $target, string $link ) : boolean Create a symlink
touch ( string $filename, integer $time = null, integer $atime = null ) : boolean Sets access and modification time of file.
truncate ( string $filename, integer $new_size ) : boolean Truncates a file to a given length

Method Details

__construct() public méthode

Connects to an SFTP server
public __construct ( string $host, integer $port = 22, integer $timeout = 10 ) : SFTP
$host string
$port integer
$timeout integer
Résultat SFTP

_close_handle() public méthode

Close handle
public _close_handle ( string $handle ) : boolean
$handle string
Résultat boolean

_comparator() public méthode

Intended for use with uasort()
public _comparator ( array $a, array $b ) : integer
$a array
$b array
Résultat integer

_delete_recursive() public méthode

Minimizes directory lookups and SSH_FXP_STATUS requests for speed.
public _delete_recursive ( string $path, integer &$i ) : boolean
$path string
$i integer
Résultat boolean

_disconnect() public méthode

Disconnect
public _disconnect ( integer $reason ) : boolean
$reason integer
Résultat boolean

_get_lstat_cache_prop() public méthode

Uses cache if appropriate.
public _get_lstat_cache_prop ( string $path, string $prop ) : mixed
$path string
$prop string
Résultat mixed

_get_sftp_packet() public méthode

See '6. General Packet Format' of draft-ietf-secsh-filexfer-13 for more info. Incidentally, the number of SSH_MSG_CHANNEL_DATA messages has no bearing on the number of SFTP packets present. There can be one SSH_MSG_CHANNEL_DATA messages containing two SFTP packets or there can be two SSH_MSG_CHANNEL_DATA messages containing one SFTP packet.
See also: self::_send_sftp_packet()
public _get_sftp_packet ( ) : string
Résultat string

_get_stat_cache_prop() public méthode

Uses cache if appropriate.
public _get_stat_cache_prop ( string $path, string $prop ) : mixed
$path string
$prop string
Résultat mixed

_get_xstat_cache_prop() public méthode

Uses cache if appropriate.
public _get_xstat_cache_prop ( string $path, string $prop, $type ) : mixed
$path string
$prop string
Résultat mixed

_list() public méthode

Reads a list, be it detailed or not, of files in the given directory
public _list ( string $dir, boolean $raw = true ) : mixed
$dir string
$raw boolean
Résultat mixed

_logError() public méthode

Logs errors
public _logError ( string $response, integer $status )
$response string
$status integer

_mkdir_helper() public méthode

Helper function for directory creation
public _mkdir_helper ( string $dir, $attr ) : boolean
$dir string
Résultat boolean

_nlist_helper() public méthode

Helper method for nlist
public _nlist_helper ( string $dir, boolean $recursive, string $relativeDir ) : mixed
$dir string
$recursive boolean
$relativeDir string
Résultat mixed

_parseAttributes() public méthode

See '7. File Attributes' of draft-ietf-secsh-filexfer-13 for more info.
public _parseAttributes ( string &$response ) : array
$response string
Résultat array

_parseLongname() public méthode

SFTPv3 doesn't provide any easy way of identifying a file type. You could try to open a file as a directory and see if an error is returned or you could try to parse the SFTPv3-specific longname field of the SSH_FXP_NAME packet. That's what this function does. The result is returned using the {@link http://tools.ietf.org/html/draft-ietf-secsh-filexfer-04#section-5.2 SFTPv4 type constants}. If the longname is in an unrecognized format bool(false) is returned.
public _parseLongname ( string $longname ) : mixed
$longname string
Résultat mixed

_parseMode() public méthode

Quoting the SFTP RFC, "Implementations MUST NOT send bits that are not defined" but they seem to anyway
public _parseMode ( integer $mode ) : integer
$mode integer
Résultat integer

_query_stat_cache() public méthode

Mainly used by file_exists
public _query_stat_cache ( $path ) : mixed
Résultat mixed

_read_put_responses() public méthode

Sending an SSH_FXP_WRITE packet and immediately reading its response isn't as efficient as blindly sending out $i SSH_FXP_WRITEs, in succession, and then reading $i responses.
public _read_put_responses ( integer $i ) : boolean
$i integer
Résultat boolean

_realpath() public méthode

SFTP doesn't provide a mechanism by which the current working directory can be changed, so we'll emulate it. Returns the absolute (canonicalized) path.
See also: self::chdir()
public _realpath ( string $path ) : mixed
$path string
Résultat mixed

_remove_from_stat_cache() public méthode

Remove files / directories from cache
public _remove_from_stat_cache ( string $path ) : boolean
$path string
Résultat boolean

_send_sftp_packet() public méthode

See '6. General Packet Format' of draft-ietf-secsh-filexfer-13 for more info.
See also: self::_get_sftp_packet()
See also: self::_send_channel_packet()
public _send_sftp_packet ( integer $type, string $data ) : boolean
$type integer
$data string
Résultat boolean

_setstat() public méthode

Sets information about a file
public _setstat ( string $filename, string $attr, boolean $recursive ) : boolean
$filename string
$attr string
$recursive boolean
Résultat boolean

_setstat_recursive() public méthode

Minimizes directory lookups and SSH_FXP_STATUS requests for speed.
public _setstat_recursive ( string $path, string $attr, integer &$i ) : boolean
$path string
$attr string
$i integer
Résultat boolean

_stat() public méthode

Determines information without calling \phpseclib\Net\SFTP::_realpath(). The second parameter can be either NET_SFTP_STAT or NET_SFTP_LSTAT.
public _stat ( string $filename, integer $type ) : mixed
$filename string
$type integer
Résultat mixed

_update_stat_cache() public méthode

Save files / directories to cache
public _update_stat_cache ( string $path, mixed $value )
$path string
$value mixed

chdir() public méthode

Changes the current directory
public chdir ( string $dir ) : boolean
$dir string
Résultat boolean

chgrp() public méthode

Returns true on success or false on error.
public chgrp ( string $filename, integer $gid, boolean $recursive = false ) : boolean
$filename string
$gid integer
$recursive boolean
Résultat boolean

chmod() public méthode

Returns the new file permissions on success or false on error. If $recursive is true than this just returns true or false.
public chmod ( integer $mode, string $filename, boolean $recursive = false ) : mixed
$mode integer
$filename string
$recursive boolean
Résultat mixed

chown() public méthode

Returns true on success or false on error.
public chown ( string $filename, integer $uid, boolean $recursive = false ) : boolean
$filename string
$uid integer
$recursive boolean
Résultat boolean

clearStatCache() public méthode

Clear the stat cache
public clearStatCache ( )

delete() public méthode

Deletes a file on the SFTP server.
public delete ( string $path, boolean $recursive = true ) : boolean
$path string
$recursive boolean
Résultat boolean

disableStatCache() public méthode

Disable the stat cache
public disableStatCache ( )

enableStatCache() public méthode

Enable the stat cache
public enableStatCache ( )

file_exists() public méthode

Checks whether a file or directory exists
public file_exists ( string $path ) : boolean
$path string
Résultat boolean

fileatime() public méthode

Gets last access time of file
public fileatime ( string $path ) : mixed
$path string
Résultat mixed

filegroup() public méthode

Gets file group
public filegroup ( string $path ) : mixed
$path string
Résultat mixed

filemtime() public méthode

Gets file modification time
public filemtime ( string $path ) : mixed
$path string
Résultat mixed

fileowner() public méthode

Gets file owner
public fileowner ( string $path ) : mixed
$path string
Résultat mixed

fileperms() public méthode

Gets file permissions
public fileperms ( string $path ) : mixed
$path string
Résultat mixed

filesize() public méthode

Gets file size
public filesize ( string $path ) : mixed
$path string
Résultat mixed

filetype() public méthode

Gets file type
public filetype ( string $path ) : mixed
$path string
Résultat mixed

get() public méthode

Returns a string containing the contents of $remote_file if $local_file is left undefined or a boolean false if the operation was unsuccessful. If $local_file is defined, returns true or false depending on the success of the operation. $offset and $length can be used to download files in chunks.
public get ( string $remote_file, string $local_file = false, integer $offset, integer $length ) : mixed
$remote_file string
$local_file string
$offset integer
$length integer
Résultat mixed

getLastSFTPError() public méthode

Returns the last error
public getLastSFTPError ( ) : string
Résultat string

getSFTPErrors() public méthode

Returns all errors
public getSFTPErrors ( ) : string
Résultat string

getSFTPLog() public méthode

Returns a string if NET_SFTP_LOGGING == self::LOG_COMPLEX, an array if NET_SFTP_LOGGING == self::LOG_SIMPLE and false if !defined('NET_SFTP_LOGGING')
public getSFTPLog ( ) : string
Résultat string or Array

getSupportedVersions() public méthode

Get supported SFTP versions
public getSupportedVersions ( ) : array
Résultat array

is_dir() public méthode

Tells whether the filename is a directory
public is_dir ( string $path ) : boolean
$path string
Résultat boolean

is_file() public méthode

Tells whether the filename is a regular file
public is_file ( string $path ) : boolean
$path string
Résultat boolean

is_readable() public méthode

Tells whether a file exists and is readable
public is_readable ( string $path ) : boolean
$path string
Résultat boolean

is_writable() public méthode

Tells whether the filename is writable
public is_writable ( string $path ) : boolean
$path string
Résultat boolean

is_writeable() public méthode

Alias of is_writable
public is_writeable ( string $path ) : boolean
$path string
Résultat boolean

login() public méthode

Login
public login ( string $username ) : boolean
$username string
Résultat boolean

lstat() public méthode

Returns an array on success and false otherwise.
public lstat ( string $filename ) : mixed
$filename string
Résultat mixed

mkdir() public méthode

Creates a directory.
public mkdir ( string $dir, $mode, $recursive = false ) : boolean
$dir string
Résultat boolean

nlist() public méthode

Returns a list of files in the given directory
public nlist ( string $dir = '.', boolean $recursive = false ) : mixed
$dir string
$recursive boolean
Résultat mixed

put() public méthode

By default, \phpseclib\Net\SFTP::put() does not read from the local filesystem. $data is dumped directly into $remote_file. So, for example, if you set $data to 'filename.ext' and then do \phpseclib\Net\SFTP::get(), you will get a file, twelve bytes long, containing 'filename.ext' as its contents. Setting $mode to self::SOURCE_LOCAL_FILE will change the above behavior. With self::SOURCE_LOCAL_FILE, $remote_file will contain as many bytes as filename.ext does on your local filesystem. If your filename.ext is 1MB then that is how large $remote_file will be, as well. Setting $mode to self::SOURCE_CALLBACK will use $data as callback function, which gets only one parameter -- number of bytes to return, and returns a string if there is some data or null if there is no more data If $data is a resource then it'll be used as a resource instead. Currently, only binary mode is supported. As such, if the line endings need to be adjusted, you will need to take care of that, yourself. $mode can take an additional two parameters - self::RESUME and self::RESUME_START. These are bitwise AND'd with $mode. So if you want to resume upload of a 300mb file on the local file system you'd set $mode to the following: self::SOURCE_LOCAL_FILE | self::RESUME If you wanted to simply append the full contents of a local file to the full contents of a remote file you'd replace self::RESUME with self::RESUME_START. If $mode & (self::RESUME | self::RESUME_START) then self::RESUME_START will be assumed. $start and $local_start give you more fine grained control over this process and take precident over self::RESUME when they're non-negative. ie. $start could let you write at the end of a file (like self::RESUME) or in the middle of one. $local_start could let you start your reading from the end of a file (like self::RESUME_START) or in the middle of one. Setting $local_start to > 0 or $mode | self::RESUME_START doesn't do anything unless $mode | self::SOURCE_LOCAL_FILE.
public put ( string $remote_file, string | resource $data, integer $mode = self::SOURCE_STRING, integer $start, integer $local_start, callable | null $progressCallback = null ) : boolean
$remote_file string
$data string | resource
$mode integer
$start integer
$local_start integer
$progressCallback callable | null
Résultat boolean

pwd() public méthode

Returns the current directory name
public pwd ( ) : mixed
Résultat mixed

rawlist() public méthode

Returns a detailed list of files in the given directory
public rawlist ( string $dir = '.', boolean $recursive = false ) : mixed
$dir string
$recursive boolean
Résultat mixed

realpath() public méthode

realpath() expands all symbolic links and resolves references to '/./', '/../' and extra '/' characters in the input path and returns the canonicalized absolute pathname.
public realpath ( string $path ) : mixed
$path string
Résultat mixed

rename() public méthode

Renames a file or a directory on the SFTP server
public rename ( string $oldname, string $newname ) : boolean
$oldname string
$newname string
Résultat boolean

rmdir() public méthode

Removes a directory.
public rmdir ( string $dir ) : boolean
$dir string
Résultat boolean

setListOrder() public méthode

If sorting is enabled directories and files will be sorted independently with directories appearing before files in the resultant array that is returned. Any parameter returned by stat is a valid sort parameter for this function. Filename comparisons are case insensitive. Examples: $sftp->setListOrder('filename', SORT_ASC); $sftp->setListOrder('size', SORT_DESC, 'filename', SORT_ASC); $sftp->setListOrder(true); Separates directories from files but doesn't do any sorting beyond that $sftp->setListOrder(); Don't do any sort of sorting
public setListOrder ( )

size() public méthode

Files larger than 4GB will show up as being exactly 4GB.
public size ( string $filename ) : mixed
$filename string
Résultat mixed

stat() public méthode

Returns an array on success and false otherwise.
public stat ( string $filename ) : mixed
$filename string
Résultat mixed

touch() public méthode

If the file does not exist, it will be created.
public touch ( string $filename, integer $time = null, integer $atime = null ) : boolean
$filename string
$time integer
$atime integer
Résultat boolean

truncate() public méthode

Truncates a file to a given length
public truncate ( string $filename, integer $new_size ) : boolean
$filename string
$new_size integer
Résultat boolean

Property Details

$extensions public_oe property

Extensions supported by the server
See also: self::_initChannel()
public array $extensions
Résultat array

$max_sftp_packet public_oe property

Max SFTP Packet Size
See also: self::__construct()
See also: self::get()
public array $max_sftp_packet
Résultat array

$packet_buffer public_oe property

Packet Buffer
See also: self::_get_sftp_packet()
public string $packet_buffer
Résultat string

$packet_log public_oe property

Packet Log
See also: self::getLog()
public array $packet_log
Résultat array

$packet_type public_oe property

The request ID exists in the off chance that a packet is sent out-of-order. Of course, this library doesn't support concurrent actions, so it's somewhat academic, here.
See also: self::_get_sftp_packet()
public int $packet_type
Résultat integer

$packet_type_log public_oe property

Packet Type Log
See also: self::getLog()
public array $packet_type_log
Résultat array

$packet_types public_oe property

Packet Types
See also: self::__construct()
public array $packet_types
Résultat array

$pwd public_oe property

Current working directory
See also: self::_realpath()
See also: self::chdir()
public string $pwd
Résultat string

$request_id public_oe property

The request ID exists in the off chance that a packet is sent out-of-order. Of course, this library doesn't support concurrent actions, so it's somewhat academic, here.
See also: self::_send_sftp_packet()
public int $request_id
Résultat integer

$sftp_errors public_oe property

Error information
See also: self::getSFTPErrors()
See also: self::getLastSFTPError()
public string $sftp_errors
Résultat string

$sortOptions public_oe property

Sort Options
See also: self::_comparator()
See also: self::setListOrder()
public array $sortOptions
Résultat array

$stat_cache public_oe property

Rather than always having to open a directory and close it immediately there after to see if a file is a directory we'll cache the results.
See also: self::_update_stat_cache()
See also: self::_remove_from_stat_cache()
See also: self::_query_stat_cache()
public array $stat_cache
Résultat array

$status_codes public_oe property

Status Codes
See also: self::__construct()
public array $status_codes
Résultat array

$use_stat_cache public_oe property

Stat Cache Flag
See also: self::disableStatCache()
See also: self::enableStatCache()
public bool $use_stat_cache
Résultat boolean

$version public_oe property

Server SFTP version
See also: self::_initChannel()
public int $version
Résultat integer