Stream
in package
SFTP Stream Wrapper
Tags
Table of Contents
- $context : resource
- Context resource
- $entries : array<string|int, mixed>
- Directory entries
- $eof : bool
- EOF flag
- $instances : array<string|int, mixed>
- SFTP instances
- $mode : string
- Mode
- $notification : callable
- Notification callback function
- $path : string
- Path
- $pos : int
- Position
- $sftp : object
- SFTP instance
- $size : int
- Size
- __call() : mixed
- __call Magic Method
- __construct() : mixed
- The Constructor
- _dir_closedir() : bool
- Close directory handle
- _dir_opendir() : bool
- Open directory handle
- _dir_readdir() : mixed
- Read entry from directory handle
- _dir_rewinddir() : bool
- Rewind directory handle
- _mkdir() : bool
- Create a directory
- _parse_path() : string
- Path Parser
- _rename() : bool
- Renames a file or directory
- _rmdir() : bool
- Removes a directory
- _stream_cast() : resource
- Retrieve the underlaying resource
- _stream_close() : mixed
- Close an resource
- _stream_eof() : bool
- Tests for end-of-file on a file pointer
- _stream_flush() : bool
- Flushes the output
- _stream_lock() : bool
- Advisory file locking
- _stream_metadata() : bool
- Change stream options
- _stream_open() : bool
- Opens file or URL
- _stream_read() : mixed
- Read from stream
- _stream_seek() : bool
- Seeks to specific location in a stream
- _stream_set_option() : bool
- Change stream options
- _stream_stat() : mixed
- Retrieve information about a file resource
- _stream_tell() : int
- Retrieve the current position of a stream
- _stream_truncate() : bool
- Truncate stream
- _stream_write() : mixed
- Write to stream
- _unlink() : bool
- Delete a file
- _url_stat() : mixed
- Retrieve information about a file
- register() : bool
- Registers this class as a URL wrapper.
Properties
$context
Context resource
public
resource
$context
Technically this needs to be publically accessible so PHP can set it directly
Tags
$entries
Directory entries
public
array<string|int, mixed>
$entries
Tags
$eof
EOF flag
public
bool
$eof
Tags
$instances
SFTP instances
public
static array<string|int, mixed>
$instances
Rather than re-create the connection we re-use instances if possible
$mode
Mode
public
string
$mode
Tags
$notification
Notification callback function
public
callable
$notification
Tags
$path
Path
public
string
$path
Tags
$pos
Position
public
int
$pos
Tags
$sftp
SFTP instance
public
object
$sftp
Tags
$size
Size
public
int
$size
Tags
Methods
__call()
__call Magic Method
public
__call(mixed $name, mixed $arguments) : mixed
When you're utilizing an SFTP stream you're not calling the methods in this class directly - PHP is calling them for you. Which kinda begs the question... what methods is PHP calling and what parameters is it passing to them? This function lets you figure that out.
If NET_SFTP_STREAM_LOGGING is defined all calls will be output on the screen and then (regardless of whether or not NET_SFTP_STREAM_LOGGING is enabled) the parameters will be passed through to the appropriate method.
Parameters
- $name : mixed
- $arguments : mixed
Tags
Return values
mixed —__construct()
The Constructor
public
__construct() : mixed
Tags
Return values
mixed —_dir_closedir()
Close directory handle
public
_dir_closedir() : bool
Tags
Return values
bool —_dir_opendir()
Open directory handle
public
_dir_opendir(string $path, int $options) : bool
The only $options is "whether or not to enforce safe_mode (0x04)". Since safe mode was deprecated in 5.3 and removed in 5.4 I'm just going to ignore it.
Also, nlist() is the best that this function is realistically going to be able to do. When an SFTP client sends a SSH_FXP_READDIR packet you don't generally get info on just one file but on multiple files. Quoting the SFTP specs:
The SSH_FXP_NAME response has the following format:
uint32 id
uint32 count
repeats count times:
string filename
string longname
ATTRS attrs
Parameters
- $path : string
- $options : int
Tags
Return values
bool —_dir_readdir()
Read entry from directory handle
public
_dir_readdir() : mixed
Tags
Return values
mixed —_dir_rewinddir()
Rewind directory handle
public
_dir_rewinddir() : bool
Tags
Return values
bool —_mkdir()
Create a directory
public
_mkdir(string $path, int $mode, int $options) : bool
Only valid $options is STREAM_MKDIR_RECURSIVE
Parameters
- $path : string
- $mode : int
- $options : int
Tags
Return values
bool —_parse_path()
Path Parser
public
_parse_path(string $path) : string
Extract a path from a URI and actually connect to an SSH server if appropriate
If "notification" is set as a context parameter the message code for successful login is NET_SSH2_MSG_USERAUTH_SUCCESS. For a failed login it's NET_SSH2_MSG_USERAUTH_FAILURE.
Parameters
- $path : string
Tags
Return values
string —_rename()
Renames a file or directory
public
_rename(string $path_from, string $path_to) : bool
Attempts to rename oldname to newname, moving it between directories if necessary. If newname exists, it will be overwritten. This is a departure from what \phpseclib\Net\SFTP does.
Parameters
- $path_from : string
- $path_to : string
Tags
Return values
bool —_rmdir()
Removes a directory
public
_rmdir(string $path, int $options) : bool
Only valid $options is STREAM_MKDIR_RECURSIVE per http://php.net/streamwrapper.rmdir, however, http://php.net/rmdir does not have a $recursive parameter as mkdir() does so I don't know how STREAM_MKDIR_RECURSIVE is supposed to be set. Also, when I try it out with rmdir() I get 8 as $options. What does 8 correspond to?
Parameters
- $path : string
- $options : int
Tags
Return values
bool —_stream_cast()
Retrieve the underlaying resource
public
_stream_cast(int $cast_as) : resource
Parameters
- $cast_as : int
Tags
Return values
resource —_stream_close()
Close an resource
public
_stream_close() : mixed
Tags
Return values
mixed —_stream_eof()
Tests for end-of-file on a file pointer
public
_stream_eof() : bool
In my testing there are four classes functions that normally effect the pointer: fseek, fputs / fwrite, fgets / fread and ftruncate.
Only fgets / fread, however, results in feof() returning true. do fputs($fp, 'aaa') on a blank file and feof() will return false. do fread($fp, 1) and feof() will then return true. do fseek($fp, 10) on ablank file and feof() will return false. do fread($fp, 1) and feof() will then return true.
Tags
Return values
bool —_stream_flush()
Flushes the output
public
_stream_flush() : bool
See http://php.net/fflush. Always returns true because \phpseclib\Net\SFTP doesn't cache stuff before writing
Tags
Return values
bool —_stream_lock()
Advisory file locking
public
_stream_lock(int $operation) : bool
Parameters
- $operation : int
Tags
Return values
bool —_stream_metadata()
Change stream options
public
_stream_metadata(string $path, int $option, mixed $var) : bool
Parameters
- $path : string
- $option : int
- $var : mixed
Tags
Return values
bool —_stream_open()
Opens file or URL
public
_stream_open(string $path, string $mode, int $options, string &$opened_path) : bool
Parameters
- $path : string
- $mode : string
- $options : int
- $opened_path : string
Tags
Return values
bool —_stream_read()
Read from stream
public
_stream_read(int $count) : mixed
Parameters
- $count : int
Tags
Return values
mixed —_stream_seek()
Seeks to specific location in a stream
public
_stream_seek(int $offset, int $whence) : bool
Parameters
- $offset : int
- $whence : int
Tags
Return values
bool —_stream_set_option()
Change stream options
public
_stream_set_option(int $option, int $arg1, int $arg2) : bool
STREAM_OPTION_WRITE_BUFFER isn't supported for the same reason stream_flush isn't. The other two aren't supported because of limitations in \phpseclib\Net\SFTP.
Parameters
- $option : int
- $arg1 : int
- $arg2 : int
Tags
Return values
bool —_stream_stat()
Retrieve information about a file resource
public
_stream_stat() : mixed
Tags
Return values
mixed —_stream_tell()
Retrieve the current position of a stream
public
_stream_tell() : int
Tags
Return values
int —_stream_truncate()
Truncate stream
public
_stream_truncate(int $new_size) : bool
Parameters
- $new_size : int
Tags
Return values
bool —_stream_write()
Write to stream
public
_stream_write(string $data) : mixed
Parameters
- $data : string
Tags
Return values
mixed —_unlink()
Delete a file
public
_unlink(string $path) : bool
Parameters
- $path : string
Tags
Return values
bool —_url_stat()
Retrieve information about a file
public
_url_stat(string $path, int $flags) : mixed
Ignores the STREAM_URL_STAT_QUIET flag because the entirety of \phpseclib\Net\SFTP\Stream is quiet by default might be worthwhile to reconstruct bits 12-16 (ie. the file type) if mode doesn't have them but we'll cross that bridge when and if it's reached
Parameters
- $path : string
- $flags : int
Tags
Return values
mixed —register()
Registers this class as a URL wrapper.
public
static register([string $protocol = 'sftp' ]) : bool
Parameters
- $protocol : string = 'sftp'
-
The wrapper name to be registered.
Tags
Return values
bool —True on success, false otherwise.