Properties

$instances

$instances : array

SFTP instances

Rather than re-create the connection we re-use instances if possible

Type

array

$sftp

$sftp : object

SFTP instance

Type

object

$path

$path : string

Path

Type

string

$mode

$mode : string

Mode

Type

string

$pos

$pos : integer

Position

Type

integer

$size

$size : integer

Size

Type

integer

$entries

$entries : array

Directory entries

Type

array

$eof

$eof : boolean

EOF flag

Type

boolean

$context

$context : resource

Context resource

Technically this needs to be publically accessible so PHP can set it directly

Type

resource

$notification

$notification : callable

Notification callback function

Type

callable

Methods

register()

register(string  $protocol = 'sftp') : boolean

Registers this class as a URL wrapper.

Parameters

string $protocol

The wrapper name to be registered.

Returns

boolean —

True on success, false otherwise.

__construct()

__construct() 

The Constructor

_parse_path()

_parse_path(string  $path) : string

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.

Parameters

string $path

Returns

string

_stream_open()

_stream_open(string  $path, string  $mode, integer  $options, string  $opened_path) : boolean

Opens file or URL

Parameters

string $path
string $mode
integer $options
string $opened_path

Returns

boolean

_stream_read()

_stream_read(integer  $count) : mixed

Read from stream

Parameters

integer $count

Returns

mixed

_stream_write()

_stream_write(string  $data) : mixed

Write to stream

Parameters

string $data

Returns

mixed

_stream_tell()

_stream_tell() : integer

Retrieve the current position of a stream

Returns

integer

_stream_eof()

_stream_eof() : boolean

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.

Returns

boolean

_stream_seek()

_stream_seek(integer  $offset, integer  $whence) : boolean

Seeks to specific location in a stream

Parameters

integer $offset
integer $whence

Returns

boolean

_stream_metadata()

_stream_metadata(string  $path, integer  $option, mixed  $var) : boolean

Change stream options

Parameters

string $path
integer $option
mixed $var

Returns

boolean

_stream_cast()

_stream_cast(integer  $cast_as) : resource

Retrieve the underlaying resource

Parameters

integer $cast_as

Returns

resource

_stream_lock()

_stream_lock(integer  $operation) : boolean

Advisory file locking

Parameters

integer $operation

Returns

boolean

_rename()

_rename(string  $path_from, string  $path_to) : boolean

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.

Parameters

string $path_from
string $path_to

Returns

boolean

_dir_opendir()

_dir_opendir(string  $path, integer  $options) : boolean

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

Parameters

string $path
integer $options

Returns

boolean

_dir_readdir()

_dir_readdir() : mixed

Read entry from directory handle

Returns

mixed

_dir_rewinddir()

_dir_rewinddir() : boolean

Rewind directory handle

Returns

boolean

_dir_closedir()

_dir_closedir() : boolean

Close directory handle

Returns

boolean

_mkdir()

_mkdir(string  $path, integer  $mode, integer  $options) : boolean

Create a directory

Only valid $options is STREAM_MKDIR_RECURSIVE

Parameters

string $path
integer $mode
integer $options

Returns

boolean

_rmdir()

_rmdir(string  $path, integer  $options) : boolean

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?

Parameters

string $path
integer $options

Returns

boolean

_stream_flush()

_stream_flush() : boolean

Flushes the output

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

Returns

boolean

_stream_stat()

_stream_stat() : mixed

Retrieve information about a file resource

Returns

mixed

_unlink()

_unlink(string  $path) : boolean

Delete a file

Parameters

string $path

Returns

boolean

_url_stat()

_url_stat(string  $path, integer  $flags) : mixed

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

Parameters

string $path
integer $flags

Returns

mixed

_stream_truncate()

_stream_truncate(integer  $new_size) : boolean

Truncate stream

Parameters

integer $new_size

Returns

boolean

_stream_set_option()

_stream_set_option(integer  $option, integer  $arg1, integer  $arg2) : boolean

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.

Parameters

integer $option
integer $arg1
integer $arg2

Returns

boolean

_stream_close()

_stream_close() 

Close an resource

__call()

__call(  $name,   $arguments) : mixed

__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.

Parameters

$name
$arguments

Returns

mixed