PHP 클래스 phpseclib\Net\SFTP

저자: Jim Wigginton ([email protected])
상속: extends SSH2
파일 보기 프로젝트 열기: phpseclib/phpseclib 1 사용 예제들

공개 프로퍼티들

프로퍼티 타입 설명
$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

공개 메소드들

메소드 설명
__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

메소드 상세

__construct() 공개 메소드

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

_close_handle() 공개 메소드

Close handle
public _close_handle ( string $handle ) : boolean
$handle string
리턴 boolean

_comparator() 공개 메소드

Intended for use with uasort()
public _comparator ( array $a, array $b ) : integer
$a array
$b array
리턴 integer

_delete_recursive() 공개 메소드

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

_disconnect() 공개 메소드

Disconnect
public _disconnect ( integer $reason ) : boolean
$reason integer
리턴 boolean

_get_lstat_cache_prop() 공개 메소드

Uses cache if appropriate.
public _get_lstat_cache_prop ( string $path, string $prop ) : mixed
$path string
$prop string
리턴 mixed

_get_sftp_packet() 공개 메소드

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.
또한 보기: self::_send_sftp_packet()
public _get_sftp_packet ( ) : string
리턴 string

_get_stat_cache_prop() 공개 메소드

Uses cache if appropriate.
public _get_stat_cache_prop ( string $path, string $prop ) : mixed
$path string
$prop string
리턴 mixed

_get_xstat_cache_prop() 공개 메소드

Uses cache if appropriate.
public _get_xstat_cache_prop ( string $path, string $prop, $type ) : mixed
$path string
$prop string
리턴 mixed

_list() 공개 메소드

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
리턴 mixed

_logError() 공개 메소드

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

_mkdir_helper() 공개 메소드

Helper function for directory creation
public _mkdir_helper ( string $dir, $attr ) : boolean
$dir string
리턴 boolean

_nlist_helper() 공개 메소드

Helper method for nlist
public _nlist_helper ( string $dir, boolean $recursive, string $relativeDir ) : mixed
$dir string
$recursive boolean
$relativeDir string
리턴 mixed

_parseAttributes() 공개 메소드

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

_parseLongname() 공개 메소드

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
리턴 mixed

_parseMode() 공개 메소드

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
리턴 integer

_query_stat_cache() 공개 메소드

Mainly used by file_exists
public _query_stat_cache ( $path ) : mixed
리턴 mixed

_read_put_responses() 공개 메소드

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
리턴 boolean

_realpath() 공개 메소드

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.
또한 보기: self::chdir()
public _realpath ( string $path ) : mixed
$path string
리턴 mixed

_remove_from_stat_cache() 공개 메소드

Remove files / directories from cache
public _remove_from_stat_cache ( string $path ) : boolean
$path string
리턴 boolean

_send_sftp_packet() 공개 메소드

See '6. General Packet Format' of draft-ietf-secsh-filexfer-13 for more info.
또한 보기: self::_get_sftp_packet()
또한 보기: self::_send_channel_packet()
public _send_sftp_packet ( integer $type, string $data ) : boolean
$type integer
$data string
리턴 boolean

_setstat() 공개 메소드

Sets information about a file
public _setstat ( string $filename, string $attr, boolean $recursive ) : boolean
$filename string
$attr string
$recursive boolean
리턴 boolean

_setstat_recursive() 공개 메소드

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
리턴 boolean

_stat() 공개 메소드

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
리턴 mixed

_update_stat_cache() 공개 메소드

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

chdir() 공개 메소드

Changes the current directory
public chdir ( string $dir ) : boolean
$dir string
리턴 boolean

chgrp() 공개 메소드

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

chmod() 공개 메소드

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
리턴 mixed

chown() 공개 메소드

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

clearStatCache() 공개 메소드

Clear the stat cache
public clearStatCache ( )

delete() 공개 메소드

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

disableStatCache() 공개 메소드

Disable the stat cache
public disableStatCache ( )

enableStatCache() 공개 메소드

Enable the stat cache
public enableStatCache ( )

file_exists() 공개 메소드

Checks whether a file or directory exists
public file_exists ( string $path ) : boolean
$path string
리턴 boolean

fileatime() 공개 메소드

Gets last access time of file
public fileatime ( string $path ) : mixed
$path string
리턴 mixed

filegroup() 공개 메소드

Gets file group
public filegroup ( string $path ) : mixed
$path string
리턴 mixed

filemtime() 공개 메소드

Gets file modification time
public filemtime ( string $path ) : mixed
$path string
리턴 mixed

fileowner() 공개 메소드

Gets file owner
public fileowner ( string $path ) : mixed
$path string
리턴 mixed

fileperms() 공개 메소드

Gets file permissions
public fileperms ( string $path ) : mixed
$path string
리턴 mixed

filesize() 공개 메소드

Gets file size
public filesize ( string $path ) : mixed
$path string
리턴 mixed

filetype() 공개 메소드

Gets file type
public filetype ( string $path ) : mixed
$path string
리턴 mixed

get() 공개 메소드

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
리턴 mixed

getLastSFTPError() 공개 메소드

Returns the last error
public getLastSFTPError ( ) : string
리턴 string

getSFTPErrors() 공개 메소드

Returns all errors
public getSFTPErrors ( ) : string
리턴 string

getSFTPLog() 공개 메소드

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
리턴 string or Array

getSupportedVersions() 공개 메소드

Get supported SFTP versions
public getSupportedVersions ( ) : array
리턴 array

is_dir() 공개 메소드

Tells whether the filename is a directory
public is_dir ( string $path ) : boolean
$path string
리턴 boolean

is_file() 공개 메소드

Tells whether the filename is a regular file
public is_file ( string $path ) : boolean
$path string
리턴 boolean

is_readable() 공개 메소드

Tells whether a file exists and is readable
public is_readable ( string $path ) : boolean
$path string
리턴 boolean

is_writable() 공개 메소드

Tells whether the filename is writable
public is_writable ( string $path ) : boolean
$path string
리턴 boolean

is_writeable() 공개 메소드

Alias of is_writable
public is_writeable ( string $path ) : boolean
$path string
리턴 boolean

login() 공개 메소드

Login
public login ( string $username ) : boolean
$username string
리턴 boolean

lstat() 공개 메소드

Returns an array on success and false otherwise.
public lstat ( string $filename ) : mixed
$filename string
리턴 mixed

mkdir() 공개 메소드

Creates a directory.
public mkdir ( string $dir, $mode, $recursive = false ) : boolean
$dir string
리턴 boolean

nlist() 공개 메소드

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

put() 공개 메소드

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
리턴 boolean

pwd() 공개 메소드

Returns the current directory name
public pwd ( ) : mixed
리턴 mixed

rawlist() 공개 메소드

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

realpath() 공개 메소드

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
리턴 mixed

rename() 공개 메소드

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

rmdir() 공개 메소드

Removes a directory.
public rmdir ( string $dir ) : boolean
$dir string
리턴 boolean

setListOrder() 공개 메소드

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() 공개 메소드

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

stat() 공개 메소드

Returns an array on success and false otherwise.
public stat ( string $filename ) : mixed
$filename string
리턴 mixed

touch() 공개 메소드

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
리턴 boolean

truncate() 공개 메소드

Truncates a file to a given length
public truncate ( string $filename, integer $new_size ) : boolean
$filename string
$new_size integer
리턴 boolean

프로퍼티 상세

$extensions 공개적으로 프로퍼티

Extensions supported by the server
또한 보기: self::_initChannel()
public array $extensions
리턴 array

$max_sftp_packet 공개적으로 프로퍼티

Max SFTP Packet Size
또한 보기: self::__construct()
또한 보기: self::get()
public array $max_sftp_packet
리턴 array

$packet_buffer 공개적으로 프로퍼티

Packet Buffer
또한 보기: self::_get_sftp_packet()
public string $packet_buffer
리턴 string

$packet_log 공개적으로 프로퍼티

Packet Log
또한 보기: self::getLog()
public array $packet_log
리턴 array

$packet_type 공개적으로 프로퍼티

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.
또한 보기: self::_get_sftp_packet()
public int $packet_type
리턴 integer

$packet_type_log 공개적으로 프로퍼티

Packet Type Log
또한 보기: self::getLog()
public array $packet_type_log
리턴 array

$packet_types 공개적으로 프로퍼티

Packet Types
또한 보기: self::__construct()
public array $packet_types
리턴 array

$pwd 공개적으로 프로퍼티

Current working directory
또한 보기: self::_realpath()
또한 보기: self::chdir()
public string $pwd
리턴 string

$request_id 공개적으로 프로퍼티

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.
또한 보기: self::_send_sftp_packet()
public int $request_id
리턴 integer

$sftp_errors 공개적으로 프로퍼티

Error information
또한 보기: self::getSFTPErrors()
또한 보기: self::getLastSFTPError()
public string $sftp_errors
리턴 string

$sortOptions 공개적으로 프로퍼티

Sort Options
또한 보기: self::_comparator()
또한 보기: self::setListOrder()
public array $sortOptions
리턴 array

$stat_cache 공개적으로 프로퍼티

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.
또한 보기: self::_update_stat_cache()
또한 보기: self::_remove_from_stat_cache()
또한 보기: self::_query_stat_cache()
public array $stat_cache
리턴 array

$status_codes 공개적으로 프로퍼티

Status Codes
또한 보기: self::__construct()
public array $status_codes
리턴 array

$use_stat_cache 공개적으로 프로퍼티

Stat Cache Flag
또한 보기: self::disableStatCache()
또한 보기: self::enableStatCache()
public bool $use_stat_cache
리턴 boolean

$version 공개적으로 프로퍼티

Server SFTP version
또한 보기: self::_initChannel()
public int $version
리턴 integer