[ Index ]

PHP Cross Reference of DokuWiki

title

Body

[close]

/vendor/phpseclib/phpseclib/phpseclib/Net/SFTP/ -> Stream.php (summary)

SFTP Stream Wrapper Creates an sftp:// protocol handler that can be used with, for example, fopen(), dir(), etc.

Author: Jim Wigginton
Copyright: 2013 Jim Wigginton
License: http://www.opensource.org/licenses/mit-license.html MIT License
Link: http://phpseclib.sourceforge.net
File Size: 795 lines (22 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class

Stream:: (27 methods):
  register()
  __construct()
  _parse_path()
  _stream_open()
  _stream_read()
  _stream_write()
  _stream_tell()
  _stream_eof()
  _stream_seek()
  _stream_metadata()
  _stream_cast()
  _stream_lock()
  _rename()
  _dir_opendir()
  _dir_readdir()
  _dir_rewinddir()
  _dir_closedir()
  _mkdir()
  _rmdir()
  _stream_flush()
  _stream_stat()
  _unlink()
  _url_stat()
  _stream_truncate()
  _stream_set_option()
  _stream_close()
  __call()


Class: Stream  - X-Ref

SFTP Stream Wrapper

register($protocol = 'sftp')   X-Ref
Registers this class as a URL wrapper.

param: string $protocol The wrapper name to be registered.
return: bool True on success, false otherwise.

__construct()   X-Ref
The Constructor


_parse_path($path)   X-Ref
Path Parser

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.

param: string $path
return: string

_stream_open($path, $mode, $options, &$opened_path)   X-Ref
Opens file or URL

param: string $path
param: string $mode
param: int $options
param: string $opened_path
return: bool

_stream_read($count)   X-Ref
Read from stream

param: int $count
return: mixed

_stream_write($data)   X-Ref
Write to stream

param: string $data
return: mixed

_stream_tell()   X-Ref
Retrieve the current position of a stream

return: int

_stream_eof()   X-Ref
Tests for end-of-file on a file pointer

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.

return: bool

_stream_seek($offset, $whence)   X-Ref
Seeks to specific location in a stream

param: int $offset
param: int $whence
return: bool

_stream_metadata($path, $option, $var)   X-Ref
Change stream options

param: string $path
param: int $option
param: mixed $var
return: bool

_stream_cast($cast_as)   X-Ref
Retrieve the underlaying resource

param: int $cast_as
return: resource

_stream_lock($operation)   X-Ref
Advisory file locking

param: int $operation
return: bool

_rename($path_from, $path_to)   X-Ref
Renames a file or directory

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.

param: string $path_from
param: string $path_to
return: bool

_dir_opendir($path, $options)   X-Ref
Open directory handle

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

param: string $path
param: int $options
return: bool

_dir_readdir()   X-Ref
Read entry from directory handle

return: mixed

_dir_rewinddir()   X-Ref
Rewind directory handle

return: bool

_dir_closedir()   X-Ref
Close directory handle

return: bool

_mkdir($path, $mode, $options)   X-Ref
Create a directory

Only valid $options is STREAM_MKDIR_RECURSIVE

param: string $path
param: int $mode
param: int $options
return: bool

_rmdir($path, $options)   X-Ref
Removes a directory

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?

param: string $path
param: int $mode
param: int $options
return: bool

_stream_flush()   X-Ref
Flushes the output

See <http://php.net/fflush>. Always returns true because \phpseclib\Net\SFTP doesn't cache stuff before writing

return: bool

_stream_stat()   X-Ref
Retrieve information about a file resource

return: mixed

_unlink($path)   X-Ref
Delete a file

param: string $path
return: bool

_url_stat($path, $flags)   X-Ref
Retrieve information about a file

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

param: string $path
param: int $flags
return: mixed

_stream_truncate($new_size)   X-Ref
Truncate stream

param: int $new_size
return: bool

_stream_set_option($option, $arg1, $arg2)   X-Ref
Change stream options

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.

param: int $option
param: int $arg1
param: int $arg2
return: bool

_stream_close()   X-Ref
Close an resource


__call($name, $arguments)   X-Ref
__call Magic Method

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.

param: string
param: array
return: mixed