Documentation

SFTP extends SSH2
in package

Pure-PHP implementations of SFTP.

Tags
author

Jim Wigginton terrafrost@php.net

access

public

Table of Contents

CHANNEL  = 0x100
SFTP channel constant
CHANNEL_AGENT_FORWARD  = 4
CHANNEL_EXEC  = 1
CHANNEL_KEEP_ALIVE  = 5
CHANNEL_SHELL  = 2
CHANNEL_SUBSYSTEM  = 3
LOG_COMPLEX  = 2
Returns the message content
LOG_MAX_SIZE  = 1048576
Make sure that the log never gets larger than this
LOG_REALTIME  = 3
Outputs the content real-time
LOG_REALTIME_FILE  = 4
Dumps the content real-time to a file
LOG_SIMPLE  = 1
Returns the message numbers
MASK_CONNECTED  = 0x2
MASK_CONSTRUCTOR  = 0x1
MASK_LOGIN  = 0x8
MASK_LOGIN_REQ  = 0x4
MASK_SHELL  = 0x10
MASK_WINDOW_ADJUST  = 0x20
READ_NEXT  = 3
Returns whenever a data packet is received.
READ_REGEX  = 2
Returns when a string matching the regular expression $expect is found
READ_SIMPLE  = 1
Returns when a string matching $expect exactly is found
RESUME  = 4
Resumes an upload
RESUME_START  = 8
Append a local file to an already existing remote file
SOURCE_CALLBACK  = 16
Reads data from callback: function callback($length) returns string to proceed, null for EOF
SOURCE_LOCAL_FILE  = 1
Reads data from a local file.
SOURCE_STRING  = 2
Reads data from a string.
$agent  : System_SSH_Agent
A System_SSH_Agent for use in the SSH2 Agent Forwarding scenario
$auth  : array<string|int, mixed>
Authentication Credentials
$bad_key_size_fix  : bool
Some versions of OpenSSH incorrectly calculate the key size
$banner_message  : string
Banner Message
$binary_packet_buffer  : string|false
Binary Packet Buffer
$bitmap  : int
Execution Bitmap
$canonicalize_paths  : bool
Canonicalization Flag
$channel_buffers  : array<string|int, mixed>
Channel Buffers
$channel_extended_data_type_codes  : array<string|int, mixed>
SSH_MSG_CHANNEL_EXTENDED_DATA's data_type_codes
$channel_open_failure_reasons  : array<string|int, mixed>
SSH_MSG_CHANNEL_OPEN_FAILURE 'reason codes', defined in RFC4254
$channel_status  : array<string|int, mixed>
Channel Status
$compression_algorithms_client_to_server  : array<string|int, mixed>|false
Compression Algorithms: Client to Server
$compression_algorithms_server_to_client  : array<string|int, mixed>|false
Compression Algorithms: Server to Client
$crypto_engine  : int
Crypto Engine
$curTimeout  : mixed
Current Timeout
$decrypt  : object
Server to Client Encryption Object
$decrypt_block_size  : int
Block Size for Client to Server Encryption
$disconnect_reasons  : array<string|int, mixed>
Disconnection Message 'reason codes' defined in RFC4253
$encrypt  : object
Client to Server Encryption Object
$encrypt_block_size  : int
Block Size for Server to Client Encryption
$encryption_algorithms_client_to_server  : array<string|int, mixed>|false
Encryption Algorithms: Client to Server
$encryption_algorithms_server_to_client  : array<string|int, mixed>|false
Encryption Algorithms: Server to Client
$errors  : string
Error information
$exchange_hash  : string
Exchange hash
$exit_status  : int
Exit status returned from ssh if any
$extensions  : array<string|int, mixed>
Extensions supported by the server
$fsock  : object
The Socket Object
$get_seq_no  : int
Get Sequence Number
$hmac_check  : object
Server to Client HMAC Object
$hmac_create  : object
Client to Server HMAC Object
$hmac_size  : int
Size of server to client HMAC
$host  : string
Hostname
$identifier  : string
The SSH identifier
$in_request_pty_exec  : bool
Flag set while exec() is running when using enablePTY()
$in_subsystem  : bool
Flag set after startSubsystem() is called
$interactiveBuffer  : array<string|int, mixed>
Interactive Buffer
$is_timeout  : bool
Did read() timeout or return normally?
$kex_algorithm  : string|false
Key Exchange Algorithm
$kex_algorithms  : array<string|int, mixed>|false
Key Exchange Algorithms
$kex_dh_group_size_max  : int
Maximum Diffie-Hellman Group Bit Size in RFC 4419 Key Exchange Methods
$kex_dh_group_size_min  : int
Minimum Diffie-Hellman Group Bit Size in RFC 4419 Key Exchange Methods
$kex_dh_group_size_preferred  : int
Preferred Diffie-Hellman Group Bit Size in RFC 4419 Key Exchange Methods
$keyboard_requests_responses  : array<string|int, mixed>
Keyboard Interactive Request / Responses
$languages_client_to_server  : array<string|int, mixed>|false
Languages: Client to Server
$languages_server_to_client  : array<string|int, mixed>|false
Languages: Server to Client
$last_interactive_response  : string
The Last Interactive Response
$last_packet  : int
Time of first network activity
$log_boundary  : string
Log Boundary
$log_long_width  : int
Log Long Width
$log_short_width  : int
Log Short Width
$log_size  : int
Current log size
$mac_algorithms_client_to_server  : array<string|int, mixed>|false
MAC Algorithms: Client to Server
$mac_algorithms_server_to_client  : array<string|int, mixed>|false
MAC Algorithms: Server to Client
$max_sftp_packet  : array<string|int, mixed>
Max SFTP Packet Size
$message_log  : array<string|int, mixed>
Message Log
$message_number_log  : array<string|int, mixed>
Message Number Log
$message_numbers  : array<string|int, mixed>
Message Numbers
$packet_buffer  : string
Packet Buffer
$packet_log  : array<string|int, mixed>
Packet Log
$packet_size_client_to_server  : array<string|int, mixed>
Packet Size
$packet_type  : int
The Packet Type
$packet_type_log  : array<string|int, mixed>
Packet Type Log
$packet_types  : array<string|int, mixed>
Packet Types
$port  : int
Port Number
$preferred  : array<string|int, mixed>
Preferred Algorithms
$preferred_signature_format  : string|false
Preferred Signature Format
$preserveTime  : bool
Preserve timestamps on file downloads / uploads
$pwd  : string
Current working directory
$quiet_mode  : mixed
Flag to suppress stderr from output
$realtime_log_file  : resource
Real-time log file pointer
$realtime_log_size  : int
Real-time log file size
$realtime_log_wrap  : mixed
Real-time log file wrap boolean
$request_pty  : bool
Flag to request a PTY when using exec()
$requestBuffer  : array<string|int, mixed>
Request Buffers
$retry_connect  : bool
Should we try to re-connect to re-establish keys?
$send_id_string_first  : bool
Send the identification string first?
$send_kex_first  : bool
Send the key exchange initiation packet first?
$send_seq_no  : int
Send Sequence Number
$server_channels  : array<string|int, mixed>
Server Channels
$server_host_key_algorithms  : array<string|int, mixed>|false
Server Host Key Algorithms
$server_identifier  : array<string|int, mixed>|false
Server Identifier
$server_public_host_key  : string
Server Public Host Key
$session_id  : string
Session identifier
$sftp_errors  : array<string|int, mixed>
Error information
$signature  : string
Server signature
$signature_format  : string
Server signature format
$signature_validated  : bool
Has the signature been validated?
$sortOptions  : array<string|int, mixed>
Sort Options
$stat_cache  : array<string|int, mixed>
Stat Cache
$status_codes  : array<string|int, mixed>
Status Codes
$stdErrorLog  : string
Contents of stdError
$terminal_modes  : array<string|int, mixed>
Terminal Modes
$timeout  : mixed
Timeout
$use_request_id  : bool
The Request ID
$use_stat_cache  : bool
Stat Cache Flag
$version  : int
Server SFTP version
$window_resize  : int
What we resize the window to
$window_size  : int
The Window Size
$window_size_client_to_server  : array<string|int, mixed>
Window size, client to server
$window_size_server_to_client  : array<string|int, mixed>
Window size, server to client
$windowColumns  : int
Number of columns for terminal window size
$windowRows  : int
Number of columns for terminal window size
__construct()  : SFTP
Default Constructor.
__destruct()  : mixed
Destructor.
_append_log()  : mixed
Logs data packets
_array_intersect_first()  : mixed
Returns the first value of the intersection of two arrays or false if the intersection is empty. The order is defined by the first parameter.
_bad_algorithm_candidate()  : bool
Tests whether or not proposed algorithm has a potential for issues
_close_channel()  : bool
Closes and flushes a channel
_close_handle()  : bool
Close handle
_comparator()  : int
Compares two rawlist entries using parameters set by setListOrder()
_connect()  : bool
Connect to an SSHv2 server
_define_array()  : mixed
Define Array
_delete_recursive()  : bool
Recursively deletes directories on the SFTP server
_disconnect()  : bool
Disconnect
_encryption_algorithm_to_crypt_instance()  : mixed
Maps an encryption algorithm name to an instance of a subclass of \phpseclib\Crypt\Base.
_encryption_algorithm_to_key_size()  : int|null
Maps an encryption algorithm name to the number of key bytes.
_filter()  : string
Filter Binary Packets
_format_log()  : string
Formats a log for printing
_format_log_helper()  : string
Helper function for _format_log
_generate_identifier()  : string
Generates the SSH identifier
_get_binary_packet()  : string
Gets Binary Packets
_get_channel_packet()  : mixed
Gets channel data
_get_interactive_channel()  : int
Return the channel to be used with read() / write()
_get_lstat_cache_prop()  : mixed
Return an lstat properity
_get_open_channel()  : int
Return an available open channel
_get_sftp_packet()  : string
Receives SFTP Packets
_get_stat_cache_prop()  : mixed
Return a stat properity
_get_xstat_cache_prop()  : mixed
Return a stat or lstat properity
_initShell()  : bool
Creates an interactive shell
_key_exchange()  : mixed
Key Exchange
_keyboard_interactive_login()  : bool
Login via keyboard-interactive authentication
_keyboard_interactive_process()  : bool
Handle the keyboard-interactive requests / responses.
_list()  : mixed
Reads a list, be it detailed or not, of files in the given directory
_logError()  : mixed
Logs errors
_login()  : bool
Login Helper
_mkdir_helper()  : bool
Helper function for directory creation
_nlist_helper()  : mixed
Helper method for nlist
_on_channel_open()  : mixed
Helper function for agent->_on_channel_open()
_parseAttributes()  : array<string|int, mixed>
Parse Attributes
_parseLongname()  : mixed
Parse Longname
_parseMode()  : int
Attempt to identify the file type
_query_stat_cache()  : mixed
Checks cache for path
_read_put_responses()  : bool
Reads multiple successive SSH_FXP_WRITE responses
_realpath()  : mixed
Canonicalize the Server-Side Path Name
_reconnect()  : bool
In situ reconnect method
_remove_from_stat_cache()  : bool
Remove files / directories from cache
_reset_connection()  : mixed
Resets a connection for re-use
_send_binary_packet()  : bool
Sends Binary Packets
_send_channel_packet()  : bool
Sends channel data
_send_sftp_packet()  : bool
Sends SFTP Packets
_setstat()  : bool
Sets information about a file
_setstat_recursive()  : bool
Recursively sets information on directories on the SFTP server
_ssh_agent_login()  : bool
Login with an ssh-agent provided key
_stat()  : mixed
Returns general information about a file or symbolic link
_string_shift()  : string
String Shift
_update_stat_cache()  : mixed
Save files / directories to cache
_updateLogHistory()  : mixed
Update packet types in log history
chdir()  : bool
Changes the current directory
chgrp()  : bool
Changes file or directory group
chmod()  : mixed
Set permissions on a file.
chown()  : bool
Changes file or directory owner
clearStatCache()  : mixed
Clear the stat cache
delete()  : bool
Deletes a file on the SFTP server.
disableDatePreservation()  : mixed
Disable Date Preservation
disablePathCanonicalization()  : mixed
Enable path canonicalization
disablePTY()  : mixed
Disable request-pty when using exec()
disableQuietMode()  : mixed
Disable Quiet Mode
disableStatCache()  : mixed
Disable the stat cache
disconnect()  : mixed
Disconnect
enableDatePreservation()  : mixed
Enable Date Preservation
enablePathCanonicalization()  : mixed
Enable path canonicalization
enablePTY()  : mixed
Enable request-pty when using exec()
enableQuietMode()  : mixed
Enable Quiet Mode
enableStatCache()  : mixed
Enable the stat cache
exec()  : string
Execute Command
file_exists()  : bool
Checks whether a file or directory exists
fileatime()  : mixed
Gets last access time of file
filegroup()  : mixed
Gets file group
filemtime()  : mixed
Gets file modification time
fileowner()  : mixed
Gets file owner
fileperms()  : mixed
Gets file permissions
filesize()  : mixed
Gets file size
filetype()  : mixed
Gets file type
get()  : mixed
Downloads a file from the SFTP server.
getAlgorithmsNegotiated()  : array<string|int, mixed>
Return list of negotiated algorithms
getBannerMessage()  : string
Returns the banner message.
getCompressionAlgorithmsClient2Server()  : array<string|int, mixed>
Return a list of the compression algorithms the server supports, when receiving stuff from the client.
getCompressionAlgorithmsServer2Client()  : array<string|int, mixed>
Return a list of the compression algorithms the server supports, when sending stuff to the client.
getEncryptionAlgorithmsClient2Server()  : array<string|int, mixed>
Return a list of the (symmetric key) encryption algorithms the server supports, when receiving stuff from the client.
getEncryptionAlgorithmsServer2Client()  : array<string|int, mixed>
Return a list of the (symmetric key) encryption algorithms the server supports, when sending stuff to the client.
getErrors()  : array<string|int, string>
Returns all errors
getExitStatus()  : false|int
Returns the exit status of an SSH command or false.
getKexAlgorithms()  : array<string|int, mixed>
Return a list of the key exchange algorithms the server supports.
getLanguagesClient2Server()  : array<string|int, mixed>
Return a list of the languages the server supports, when receiving stuff from the client.
getLanguagesServer2Client()  : array<string|int, mixed>
Return a list of the languages the server supports, when sending stuff to the client.
getLastError()  : string
Returns the last error
getLastSFTPError()  : string
Returns the last error
getLog()  : array<string|int, mixed>|false|string
Returns a log of the packets that have been sent and received.
getMACAlgorithmsClient2Server()  : array<string|int, mixed>
Return a list of the MAC algorithms the server supports, when receiving stuff from the client.
getMACAlgorithmsServer2Client()  : array<string|int, mixed>
Return a list of the MAC algorithms the server supports, when sending stuff to the client.
getServerAlgorithms()  : array<string|int, mixed>
Returns a list of algorithms the server supports
getServerHostKeyAlgorithms()  : array<string|int, mixed>
Return a list of the host key (public key) algorithms the server supports.
getServerIdentification()  : string
Return the server identification.
getServerPublicHostKey()  : mixed
Returns the server public host key.
getSFTPErrors()  : array<string|int, mixed>
Returns all errors
getSFTPLog()  : string
Returns a log of the packets that have been sent and received.
getStdError()  : mixed
Get the output from stdError
getSupportedCompressionAlgorithms()  : array<string|int, mixed>
Returns a list of compression algorithms that phpseclib supports
getSupportedEncryptionAlgorithms()  : array<string|int, mixed>
Returns a list of symmetric key algorithms that phpseclib supports
getSupportedHostKeyAlgorithms()  : array<string|int, mixed>
Returns a list of host key algorithms that phpseclib supports
getSupportedKEXAlgorithms()  : array<string|int, mixed>
Returns a list of KEX algorithms that phpseclib supports
getSupportedMACAlgorithms()  : array<string|int, mixed>
Returns a list of MAC algorithms that phpseclib supports
getSupportedVersions()  : array<string|int, mixed>
Get supported SFTP versions
getWindowColumns()  : int
Returns the number of columns for the terminal window size.
getWindowRows()  : int
Returns the number of rows for the terminal window size.
is_dir()  : bool
Tells whether the filename is a directory
is_file()  : bool
Tells whether the filename is a regular file
is_link()  : bool
Tells whether the filename is a symbolic link
is_readable()  : bool
Tells whether a file exists and is readable
is_writable()  : bool
Tells whether the filename is writable
is_writeable()  : bool
Tells whether the filename is writeable
isAuthenticated()  : bool
Have you successfully been logged in?
isConnected()  : bool
Is the connection still active?
isPTYEnabled()  : bool
Returns whether request-pty is enabled or not
isQuietModeEnabled()  : bool
Returns whether Quiet Mode is enabled or not
isTimeout()  : mixed
Is timeout?
login()  : bool
Login
lstat()  : mixed
Returns general information about a file or symbolic link.
mkdir()  : bool
Creates a directory.
nlist()  : mixed
Returns a list of files in the given directory
ping()  : bool
Pings a server connection, or tries to reconnect if the connection has gone down
pwd()  : mixed
Returns the current directory name
rawlist()  : mixed
Returns a detailed list of files in the given directory
read()  : string|bool
Returns the output of an interactive shell
readlink()  : mixed
Return the target of a symbolic link
realpath()  : mixed
Returns canonicalized absolute pathname
rename()  : bool
Renames a file or a directory on the SFTP server
reset()  : mixed
Closes a channel
rmdir()  : bool
Removes a directory.
sendIdentificationStringFirst()  : mixed
Send Identification String First
sendIdentificationStringLast()  : mixed
Send Identification String Last
sendKEXINITFirst()  : mixed
Send SSH_MSG_KEXINIT First
sendKEXINITLast()  : mixed
Send SSH_MSG_KEXINIT Last
setCryptoEngine()  : mixed
Set Crypto Engine Mode
setListOrder()  : mixed
Defines how nlist() and rawlist() will be sorted - if at all.
setPreferredAlgorithms()  : mixed
Accepts an associative array with up to four parameters as described at <https://www.php.net/manual/en/function.ssh2-connect.php>
setTimeout()  : mixed
Set Timeout
setWindowColumns()  : mixed
Sets the number of columns for the terminal window size.
setWindowRows()  : mixed
Sets the number of rows for the terminal window size.
setWindowSize()  : mixed
Sets the number of columns and rows for the terminal window size.
size()  : mixed
Returns the file size, in bytes, or false, on failure
startSubsystem()  : bool
Start a subsystem.
stat()  : mixed
Returns general information about a file.
stopSubsystem()  : bool
Stops a subsystem.
symlink()  : bool
Create a symlink
touch()  : bool
Sets access and modification time of file.
truncate()  : bool
Truncates a file to a given length
write()  : bool
Inputs a command into an interactive shell.

Constants

CHANNEL_AGENT_FORWARD

public mixed CHANNEL_AGENT_FORWARD = 4

CHANNEL_EXEC

public mixed CHANNEL_EXEC = 1

CHANNEL_KEEP_ALIVE

public mixed CHANNEL_KEEP_ALIVE = 5

CHANNEL_SHELL

public mixed CHANNEL_SHELL = 2

CHANNEL_SUBSYSTEM

public mixed CHANNEL_SUBSYSTEM = 3

LOG_COMPLEX

Returns the message content

public mixed LOG_COMPLEX = 2

LOG_MAX_SIZE

Make sure that the log never gets larger than this

public mixed LOG_MAX_SIZE = 1048576

LOG_REALTIME

Outputs the content real-time

public mixed LOG_REALTIME = 3

LOG_REALTIME_FILE

Dumps the content real-time to a file

public mixed LOG_REALTIME_FILE = 4

LOG_SIMPLE

Returns the message numbers

public mixed LOG_SIMPLE = 1

MASK_CONNECTED

public mixed MASK_CONNECTED = 0x2

MASK_CONSTRUCTOR

public mixed MASK_CONSTRUCTOR = 0x1

MASK_LOGIN

public mixed MASK_LOGIN = 0x8

MASK_LOGIN_REQ

public mixed MASK_LOGIN_REQ = 0x4

MASK_SHELL

public mixed MASK_SHELL = 0x10

MASK_WINDOW_ADJUST

public mixed MASK_WINDOW_ADJUST = 0x20

READ_NEXT

Returns whenever a data packet is received.

public mixed READ_NEXT = 3

Some data packets may only contain a single character so it may be necessary to call read() multiple times when using this option

READ_REGEX

Returns when a string matching the regular expression $expect is found

public mixed READ_REGEX = 2

READ_SIMPLE

Returns when a string matching $expect exactly is found

public mixed READ_SIMPLE = 1

RESUME

Resumes an upload

public mixed RESUME = 4

RESUME_START

Append a local file to an already existing remote file

public mixed RESUME_START = 8

SOURCE_CALLBACK

Reads data from callback: function callback($length) returns string to proceed, null for EOF

public mixed SOURCE_CALLBACK = 16

SOURCE_LOCAL_FILE

Reads data from a local file.

public mixed SOURCE_LOCAL_FILE = 1

SOURCE_STRING

Reads data from a string.

public mixed SOURCE_STRING = 2

Properties

$agent

A System_SSH_Agent for use in the SSH2 Agent Forwarding scenario

public System_SSH_Agent $agent
Tags
access

private

$auth

Authentication Credentials

public array<string|int, mixed> $auth = array()
Tags
access

private

$bad_key_size_fix

Some versions of OpenSSH incorrectly calculate the key size

public bool $bad_key_size_fix = false
Tags
access

private

$banner_message

Banner Message

public string $banner_message = ''

Quoting from the RFC, "in some jurisdictions, sending a warning message before authentication may be relevant for getting legal protection."

Tags
see
self::_filter()
see
self::getBannerMessage()
access

private

$binary_packet_buffer

Binary Packet Buffer

public string|false $binary_packet_buffer = false
Tags
access

private

$bitmap

Execution Bitmap

public int $bitmap = 0

The bits that are set represent functions that have been called already. This is used to determine if a requisite function has been successfully executed. If not, an error should be thrown.

Tags
access

private

$canonicalize_paths

Canonicalization Flag

public bool $canonicalize_paths = true

Determines whether or not paths should be canonicalized before being passed on to the remote server.

Tags
see
self::enablePathCanonicalization()
see
self::disablePathCanonicalization()
see
self::realpath()
access

private

$channel_buffers

Channel Buffers

public array<string|int, mixed> $channel_buffers = array()

If a client requests a packet from one channel but receives two packets from another those packets should be placed in a buffer

Tags
see
self::_get_channel_packet()
see
self::exec()
access

private

$channel_open_failure_reasons

SSH_MSG_CHANNEL_OPEN_FAILURE 'reason codes', defined in RFC4254

public array<string|int, mixed> $channel_open_failure_reasons = array()
Tags
see
self::__construct()
access

private

$channel_status

Channel Status

public array<string|int, mixed> $channel_status = array()

Contains the type of the last sent message

Tags
see
self::_get_channel_packet()
access

private

$compression_algorithms_client_to_server

Compression Algorithms: Client to Server

public array<string|int, mixed>|false $compression_algorithms_client_to_server = false
Tags
see
self::getCompressionAlgorithmsClient2Server()
access

private

$compression_algorithms_server_to_client

Compression Algorithms: Server to Client

public array<string|int, mixed>|false $compression_algorithms_server_to_client = false
Tags
see
self::getCompressionAlgorithmsServer2Client()
access

private

$crypto_engine

Crypto Engine

public int $crypto_engine = false
Tags
see
self::setCryptoEngine()
see
self::_key_exchange()
access

private

$curTimeout

Current Timeout

public mixed $curTimeout
Tags
see
self::_get_channel_packet()
access

private

$decrypt

Server to Client Encryption Object

public object $decrypt = false
Tags
see
self::_get_binary_packet()
access

private

$decrypt_block_size

Block Size for Client to Server Encryption

public int $decrypt_block_size = 8
Tags
see
self::__construct()
see
self::_get_binary_packet()
access

private

$disconnect_reasons

Disconnection Message 'reason codes' defined in RFC4253

public array<string|int, mixed> $disconnect_reasons = array()
Tags
see
self::__construct()
access

private

$encrypt

Client to Server Encryption Object

public object $encrypt = false
Tags
see
self::_send_binary_packet()
access

private

$encrypt_block_size

Block Size for Server to Client Encryption

public int $encrypt_block_size = 8

"Note that the length of the concatenation of 'packet_length', 'padding_length', 'payload', and 'random padding' MUST be a multiple of the cipher block size or 8, whichever is larger. This constraint MUST be enforced, even when using stream ciphers."

-- http://tools.ietf.org/html/rfc4253#section-6

Tags
see
self::__construct()
see
self::_send_binary_packet()
access

private

$encryption_algorithms_client_to_server

Encryption Algorithms: Client to Server

public array<string|int, mixed>|false $encryption_algorithms_client_to_server = false
Tags
see
self::getEncryptionAlgorithmsClient2Server()
access

private

$encryption_algorithms_server_to_client

Encryption Algorithms: Server to Client

public array<string|int, mixed>|false $encryption_algorithms_server_to_client = false
Tags
see
self::getEncryptionAlgorithmsServer2Client()
access

private

$errors

Error information

public string $errors = array()
Tags
see
self::getErrors()
see
self::getLastError()
access

private

$exchange_hash

Exchange hash

public string $exchange_hash = false

The current exchange hash

Tags
see
self::_key_exchange()
access

private

$exit_status

Exit status returned from ssh if any

public int $exit_status
Tags
access

private

$extensions

Extensions supported by the server

public array<string|int, mixed> $extensions = array()
Tags
see
self::_initChannel()
access

private

$fsock

The Socket Object

public object $fsock
Tags
access

private

$get_seq_no

Get Sequence Number

public int $get_seq_no = 0

See 'Section 6.4. Data Integrity' of rfc4253 for more info.

Tags
see
self::_get_binary_packet()
access

private

$hmac_check

Server to Client HMAC Object

public object $hmac_check = false
Tags
see
self::_get_binary_packet()
access

private

$hmac_create

Client to Server HMAC Object

public object $hmac_create = false
Tags
see
self::_send_binary_packet()
access

private

$hmac_size

Size of server to client HMAC

public int $hmac_size = false

We need to know how big the HMAC will be for the server to client direction so that we know how many bytes to read. For the client to server side, the HMAC object will make the HMAC as long as it needs to be. All we need to do is append it.

Tags
see
self::_get_binary_packet()
access

private

$host

Hostname

public string $host
Tags
see
self::__construct()
see
self::_connect()
access

private

$identifier

The SSH identifier

public string $identifier
Tags
access

private

$in_request_pty_exec

Flag set while exec() is running when using enablePTY()

public bool $in_request_pty_exec = false
Tags
access

private

$in_subsystem

Flag set after startSubsystem() is called

public bool $in_subsystem
Tags
access

private

$interactiveBuffer

Interactive Buffer

public array<string|int, mixed> $interactiveBuffer = ''
Tags
see
self::read()
access

private

$is_timeout

Did read() timeout or return normally?

public bool $is_timeout = false
Tags
see
self::isTimeout()
access

private

$kex_algorithm

Key Exchange Algorithm

public string|false $kex_algorithm = false
Tags
see
self::getMethodsNegotiated()
access

private

$kex_algorithms

Key Exchange Algorithms

public array<string|int, mixed>|false $kex_algorithms = false
Tags
see
self::getKexAlgorithims()
access

private

$kex_dh_group_size_max

Maximum Diffie-Hellman Group Bit Size in RFC 4419 Key Exchange Methods

public int $kex_dh_group_size_max = 4096
Tags
see
self::_key_exchange()
access

private

$kex_dh_group_size_min

Minimum Diffie-Hellman Group Bit Size in RFC 4419 Key Exchange Methods

public int $kex_dh_group_size_min = 1536
Tags
see
self::_key_exchange()
access

private

$kex_dh_group_size_preferred

Preferred Diffie-Hellman Group Bit Size in RFC 4419 Key Exchange Methods

public int $kex_dh_group_size_preferred = 2048
Tags
see
self::_key_exchange()
access

private

$keyboard_requests_responses

Keyboard Interactive Request / Responses

public array<string|int, mixed> $keyboard_requests_responses = array()
Tags
see
self::_keyboard_interactive_process()
access

private

$languages_client_to_server

Languages: Client to Server

public array<string|int, mixed>|false $languages_client_to_server = false
Tags
see
self::getLanguagesClient2Server()
access

private

$languages_server_to_client

Languages: Server to Client

public array<string|int, mixed>|false $languages_server_to_client = false
Tags
see
self::getLanguagesServer2Client()
access

private

$last_interactive_response

The Last Interactive Response

public string $last_interactive_response = ''
Tags
see
self::_keyboard_interactive_process()
access

private

$last_packet

Time of first network activity

public int $last_packet
Tags
access

private

$log_boundary

Log Boundary

public string $log_boundary = ':'
Tags
see
self::_format_log()
access

private

$log_long_width

Log Long Width

public int $log_long_width = 65
Tags
see
self::_format_log()
access

private

$log_short_width

Log Short Width

public int $log_short_width = 16
Tags
see
self::_format_log()
access

private

$log_size

Current log size

public int $log_size

Should never exceed self::LOG_MAX_SIZE

Tags
see
self::_send_binary_packet()
see
self::_get_binary_packet()
access

private

$mac_algorithms_client_to_server

MAC Algorithms: Client to Server

public array<string|int, mixed>|false $mac_algorithms_client_to_server = false
Tags
see
self::getMACAlgorithmsClient2Server()
access

private

$mac_algorithms_server_to_client

MAC Algorithms: Server to Client

public array<string|int, mixed>|false $mac_algorithms_server_to_client = false
Tags
see
self::getMACAlgorithmsServer2Client()
access

private

$max_sftp_packet

Max SFTP Packet Size

public array<string|int, mixed> $max_sftp_packet
Tags
see
self::__construct()
see
self::get()
access

private

$message_log

Message Log

public array<string|int, mixed> $message_log = array()
Tags
see
self::getLog()
access

private

$message_number_log

Message Number Log

public array<string|int, mixed> $message_number_log = array()
Tags
see
self::getLog()
access

private

$message_numbers

Message Numbers

public array<string|int, mixed> $message_numbers = array()
Tags
see
self::__construct()
access

private

$packet_buffer

Packet Buffer

public string $packet_buffer = ''
Tags
see
self::_get_sftp_packet()
access

private

$packet_log

Packet Log

public array<string|int, mixed> $packet_log = array()
Tags
see
self::getLog()
access

private

$packet_size_client_to_server

Packet Size

public array<string|int, mixed> $packet_size_client_to_server = array()

Maximum packet size indexed by channel

Tags
see
self::_send_channel_packet()
access

private

$packet_type

The Packet Type

public int $packet_type = -1

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.

Tags
see
self::_get_sftp_packet()
access

private

$packet_type_log

Packet Type Log

public array<string|int, mixed> $packet_type_log = array()
Tags
see
self::getLog()
access

private

$packet_types

Packet Types

public array<string|int, mixed> $packet_types = array()
Tags
see
self::__construct()
access

private

$port

Port Number

public int $port
Tags
see
self::__construct()
see
self::_connect()
access

private

$preferred

Preferred Algorithms

public array<string|int, mixed> $preferred = array()
Tags
see
self::setPreferredAlgorithms()
access

private

$preferred_signature_format

Preferred Signature Format

public string|false $preferred_signature_format = false
Tags
access

private

$preserveTime

Preserve timestamps on file downloads / uploads

public bool $preserveTime = false
Tags
see
self::get()
see
self::put()
access

private

$pwd

Current working directory

public string $pwd = false
Tags
see
self::realpath()
see
self::chdir()
access

private

$quiet_mode

Flag to suppress stderr from output

public mixed $quiet_mode = false
Tags
see
self::enableQuietMode()
access

private

$realtime_log_file

Real-time log file pointer

public resource $realtime_log_file
Tags
see
self::_append_log()
access

private

$realtime_log_size

Real-time log file size

public int $realtime_log_size
Tags
see
self::_append_log()
access

private

$realtime_log_wrap

Real-time log file wrap boolean

public mixed $realtime_log_wrap
Tags
see
self::_append_log()
access

private

$request_pty

Flag to request a PTY when using exec()

public bool $request_pty = false
Tags
see
self::enablePTY()
access

private

$requestBuffer

Request Buffers

public array<string|int, mixed> $requestBuffer = array()
Tags
see
self::_get_sftp_packet()
access

private

$retry_connect

Should we try to re-connect to re-establish keys?

public bool $retry_connect = false
Tags
access

private

$send_id_string_first

Send the identification string first?

public bool $send_id_string_first = true
Tags
access

private

$send_kex_first

Send the key exchange initiation packet first?

public bool $send_kex_first = true
Tags
access

private

$send_seq_no

Send Sequence Number

public int $send_seq_no = 0

See 'Section 6.4. Data Integrity' of rfc4253 for more info.

Tags
see
self::_send_binary_packet()
access

private

$server_channels

Server Channels

public array<string|int, mixed> $server_channels = array()

Maps client channels to server channels

Tags
see
self::_get_channel_packet()
see
self::exec()
access

private

$server_host_key_algorithms

Server Host Key Algorithms

public array<string|int, mixed>|false $server_host_key_algorithms = false
Tags
see
self::getServerHostKeyAlgorithms()
access

private

$server_identifier

Server Identifier

public array<string|int, mixed>|false $server_identifier = false
Tags
see
self::getServerIdentification()
access

private

$server_public_host_key

Server Public Host Key

public string $server_public_host_key
Tags
see
self::getServerPublicHostKey()
access

private

$session_id

Session identifier

public string $session_id = false

"The exchange hash H from the first key exchange is additionally used as the session identifier, which is a unique identifier for this connection."

-- http://tools.ietf.org/html/rfc4253#section-7.2

Tags
see
self::_key_exchange()
access

private

$sftp_errors

Error information

public array<string|int, mixed> $sftp_errors = array()
Tags
see
self::getSFTPErrors()
see
self::getLastSFTPError()
access

private

$signature

Server signature

public string $signature = ''

Verified against $this->session_id

Tags
see
self::getServerPublicHostKey()
access

private

$signature_format

Server signature format

public string $signature_format = ''

ssh-rsa or ssh-dss.

Tags
see
self::getServerPublicHostKey()
access

private

$signature_validated

Has the signature been validated?

public bool $signature_validated = false
Tags
see
self::getServerPublicHostKey()
access

private

$sortOptions

Sort Options

public array<string|int, mixed> $sortOptions = array()
Tags
see
self::_comparator()
see
self::setListOrder()
access

private

$stat_cache

Stat Cache

public array<string|int, mixed> $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.

Tags
see
self::_update_stat_cache()
see
self::_remove_from_stat_cache()
see
self::_query_stat_cache()
access

private

$status_codes

Status Codes

public array<string|int, mixed> $status_codes = array()
Tags
see
self::__construct()
access

private

$stdErrorLog

Contents of stdError

public string $stdErrorLog
Tags
access

private

$timeout

Timeout

public mixed $timeout
Tags
see
self::setTimeout()
access

private

$use_request_id

The Request ID

public bool $use_request_id = false

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.

Tags
see
self::_send_sftp_packet()
access

private

$use_stat_cache

Stat Cache Flag

public bool $use_stat_cache = true
Tags
see
self::disableStatCache()
see
self::enableStatCache()
access

private

$version

Server SFTP version

public int $version
Tags
see
self::_initChannel()
access

private

$window_resize

What we resize the window to

public int $window_resize = 0x40000000

When PuTTY resizes the window it doesn't add an additional 0x7FFFFFFF bytes - it adds 0x40000000 bytes. Some SFTP clients (GoAnywhere) don't support adding 0x7FFFFFFF to the window size after the fact so we'll just do what PuTTY does

Tags
see
self::_send_channel_packet()
see
self::exec()
access

private

$window_size

The Window Size

public int $window_size = 0x7fffffff

Bytes the other party can send before it must wait for the window to be adjusted (0x7FFFFFFF = 2GB)

Tags
see
self::_send_channel_packet()
see
self::exec()
access

private

$window_size_client_to_server

Window size, client to server

public array<string|int, mixed> $window_size_client_to_server = array()

Window size indexed by channel

Tags
see
self::_get_channel_packet()
access

private

$window_size_server_to_client

Window size, server to client

public array<string|int, mixed> $window_size_server_to_client = array()

Window size indexed by channel

Tags
see
self::_send_channel_packet()
access

private

$windowColumns

Number of columns for terminal window size

public int $windowColumns = 80
Tags
see
self::getWindowColumns()
see
self::setWindowColumns()
see
self::setWindowSize()
access

private

$windowRows

Number of columns for terminal window size

public int $windowRows = 24
Tags
see
self::getWindowRows()
see
self::setWindowRows()
see
self::setWindowSize()
access

private

Methods

__construct()

Default Constructor.

public __construct(string $host[, int $port = 22 ][, int $timeout = 10 ]) : SFTP

Connects to an SFTP server

Parameters
$host : string
$port : int = 22
$timeout : int = 10
Tags
access

public

Return values
SFTP

__destruct()

Destructor.

public __destruct() : mixed

Will be called, automatically, if you're supporting just PHP5. If you're supporting PHP4, you'll need to call disconnect().

Tags
access

public

Return values
mixed

_append_log()

Logs data packets

public _append_log(mixed $message_number, mixed $message) : mixed

Makes sure that only the last 1MB worth of packets will be logged

Parameters
$message_number : mixed
$message : mixed
Tags
access

private

Return values
mixed

_array_intersect_first()

Returns the first value of the intersection of two arrays or false if the intersection is empty. The order is defined by the first parameter.

public _array_intersect_first(array<string|int, mixed> $array1, array<string|int, mixed> $array2) : mixed
Parameters
$array1 : array<string|int, mixed>
$array2 : array<string|int, mixed>
Tags
access

private

Return values
mixed

False if intersection is empty, else intersected value.

_close_channel()

Closes and flushes a channel

public _close_channel(int $client_channel[, bool $want_reply = false ]) : bool

\phpseclib\Net\SSH2 doesn't properly close most channels. For exec() channels are normally closed by the server and for SFTP channels are presumably closed when the client disconnects. This functions is intended for SCP more than anything.

Parameters
$client_channel : int
$want_reply : bool = false
Tags
access

private

Return values
bool

_close_handle()

Close handle

public _close_handle(string $handle) : bool
Parameters
$handle : string
Tags
access

private

Return values
bool

_comparator()

Compares two rawlist entries using parameters set by setListOrder()

public _comparator(array<string|int, mixed> $a, array<string|int, mixed> $b) : int

Intended for use with uasort()

Parameters
$a : array<string|int, mixed>
$b : array<string|int, mixed>
Tags
access

private

Return values
int

_connect()

Connect to an SSHv2 server

public _connect() : bool
Tags
access

private

Return values
bool

_define_array()

Define Array

public _define_array() : mixed

Takes any number of arrays whose indices are integers and whose values are strings and defines a bunch of named constants from it, using the value as the name of the constant and the index as the value of the constant. If any of the constants that would be defined already exists, none of the constants will be defined.

Tags
access

private

Return values
mixed

_delete_recursive()

Recursively deletes directories on the SFTP server

public _delete_recursive(string $path, int &$i) : bool

Minimizes directory lookups and SSH_FXP_STATUS requests for speed.

Parameters
$path : string
$i : int
Tags
access

private

Return values
bool

_disconnect()

Disconnect

public _disconnect(int $reason) : bool
Parameters
$reason : int
Tags
access

private

Return values
bool

_encryption_algorithm_to_crypt_instance()

Maps an encryption algorithm name to an instance of a subclass of \phpseclib\Crypt\Base.

public _encryption_algorithm_to_crypt_instance(string $algorithm) : mixed
Parameters
$algorithm : string

Name of the encryption algorithm

Tags
access

private

Return values
mixed

Instance of \phpseclib\Crypt\Base or null for unknown

_encryption_algorithm_to_key_size()

Maps an encryption algorithm name to the number of key bytes.

public _encryption_algorithm_to_key_size(string $algorithm) : int|null
Parameters
$algorithm : string

Name of the encryption algorithm

Tags
access

private

Return values
int|null

Number of bytes as an integer or null for unknown

_filter()

Filter Binary Packets

public _filter(mixed $payload, mixed $skip_channel_filter) : string

Because some binary packets need to be ignored...

Parameters
$payload : mixed
$skip_channel_filter : mixed
Tags
see
self::_get_binary_packet()
access

private

Return values
string

_format_log()

Formats a log for printing

public _format_log(array<string|int, mixed> $message_log, array<string|int, mixed> $message_number_log) : string
Parameters
$message_log : array<string|int, mixed>
$message_number_log : array<string|int, mixed>
Tags
access

private

Return values
string

_format_log_helper()

Helper function for _format_log

public _format_log_helper(array<string|int, mixed> $matches) : string

For use with preg_replace_callback()

Parameters
$matches : array<string|int, mixed>
Tags
access

private

Return values
string

_generate_identifier()

Generates the SSH identifier

public _generate_identifier() : string

You should overwrite this method in your own class if you want to use another identifier

Tags
access

protected

Return values
string

_get_binary_packet()

Gets Binary Packets

public _get_binary_packet([mixed $skip_channel_filter = false ]) : string

See '6. Binary Packet Protocol' of rfc4253 for more info.

Parameters
$skip_channel_filter : mixed = false
Tags
see
self::_send_binary_packet()
access

private

Return values
string

_get_channel_packet()

Gets channel data

public _get_channel_packet( $client_channel[, mixed $skip_extended = false ]) : mixed

Returns the data as a string if it's available and false if not.

Parameters
$client_channel :
$skip_extended : mixed = false
Tags
access

private

Return values
mixed

_get_interactive_channel()

Return the channel to be used with read() / write()

public _get_interactive_channel() : int
Tags
see
self::read()
see
self::write()
access

public

Return values
int

_get_lstat_cache_prop()

Return an lstat properity

public _get_lstat_cache_prop(string $path, string $prop) : mixed

Uses cache if appropriate.

Parameters
$path : string
$prop : string
Tags
access

private

Return values
mixed

_get_open_channel()

Return an available open channel

public _get_open_channel() : int
Tags
access

public

Return values
int

_get_sftp_packet()

Receives SFTP Packets

public _get_sftp_packet([mixed $request_id = null ]) : string

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.

Parameters
$request_id : mixed = null
Tags
see
self::_send_sftp_packet()
access

private

Return values
string

_get_stat_cache_prop()

Return a stat properity

public _get_stat_cache_prop(string $path, string $prop) : mixed

Uses cache if appropriate.

Parameters
$path : string
$prop : string
Tags
access

private

Return values
mixed

_get_xstat_cache_prop()

Return a stat or lstat properity

public _get_xstat_cache_prop(string $path, string $prop, mixed $type) : mixed

Uses cache if appropriate.

Parameters
$path : string
$prop : string
$type : mixed
Tags
access

private

Return values
mixed

_initShell()

Creates an interactive shell

public _initShell() : bool
Tags
see
self::read()
see
self::write()
access

private

Return values
bool

_key_exchange()

Key Exchange

public _key_exchange([string $kexinit_payload_server = false ]) : mixed
Parameters
$kexinit_payload_server : string = false

optional

Tags
access

private

Return values
mixed

_keyboard_interactive_login()

Login via keyboard-interactive authentication

public _keyboard_interactive_login(string $username, string $password) : bool

See RFC4256 for details. This is not a full-featured keyboard-interactive authenticator.

Parameters
$username : string
$password : string
Tags
access

private

Return values
bool

_keyboard_interactive_process()

Handle the keyboard-interactive requests / responses.

public _keyboard_interactive_process() : bool
Tags
access

private

Return values
bool

_list()

Reads a list, be it detailed or not, of files in the given directory

public _list(string $dir[, bool $raw = true ]) : mixed
Parameters
$dir : string
$raw : bool = true
Tags
access

private

Return values
mixed

_logError()

Logs errors

public _logError(string $response[, int $status = -1 ]) : mixed
Parameters
$response : string
$status : int = -1
Tags
access

public

Return values
mixed

_login()

Login Helper

public _login(string $username) : bool
Parameters
$username : string
Tags
see
self::_login_helper()
access

private

Return values
bool

_mkdir_helper()

Helper function for directory creation

public _mkdir_helper(string $dir, mixed $mode) : bool
Parameters
$dir : string
$mode : mixed
Tags
access

private

Return values
bool

_nlist_helper()

Helper method for nlist

public _nlist_helper(string $dir, bool $recursive, string $relativeDir) : mixed
Parameters
$dir : string
$recursive : bool
$relativeDir : string
Tags
access

private

Return values
mixed

_on_channel_open()

Helper function for agent->_on_channel_open()

public _on_channel_open() : mixed

Used when channels are created to inform agent of said channel opening. Must be called after channel open confirmation received

Tags
access

private

Return values
mixed

_parseAttributes()

Parse Attributes

public _parseAttributes(string &$response) : array<string|int, mixed>

See '7. File Attributes' of draft-ietf-secsh-filexfer-13 for more info.

Parameters
$response : string
Tags
access

private

Return values
array<string|int, mixed>

_parseLongname()

Parse Longname

public _parseLongname(string $longname) : mixed

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 SFTPv4 type constants.

If the longname is in an unrecognized format bool(false) is returned.

Parameters
$longname : string
Tags
access

private

Return values
mixed

_parseMode()

Attempt to identify the file type

public _parseMode(int $mode) : int

Quoting the SFTP RFC, "Implementations MUST NOT send bits that are not defined" but they seem to anyway

Parameters
$mode : int
Tags
access

private

Return values
int

_query_stat_cache()

Checks cache for path

public _query_stat_cache(mixed $path) : mixed

Mainly used by file_exists

Parameters
$path : mixed
Tags
access

private

Return values
mixed

_read_put_responses()

Reads multiple successive SSH_FXP_WRITE responses

public _read_put_responses(int $i) : bool

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.

Parameters
$i : int
Tags
access

private

Return values
bool

_realpath()

Canonicalize the Server-Side Path Name

public _realpath(string $path) : mixed

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.

If canonicalize_paths has been disabled using disablePathCanonicalization(), $path is returned as-is.

Parameters
$path : string
Tags
see
self::chdir()
see
self::disablePathCanonicalization()
access

private

Return values
mixed

_reconnect()

In situ reconnect method

public _reconnect() : bool
Tags
access

private

Return values
bool

_remove_from_stat_cache()

Remove files / directories from cache

public _remove_from_stat_cache(string $path) : bool
Parameters
$path : string
Tags
access

private

Return values
bool

_reset_connection()

Resets a connection for re-use

public _reset_connection(int $reason) : mixed
Parameters
$reason : int
Tags
access

private

Return values
mixed

_send_binary_packet()

Sends Binary Packets

public _send_binary_packet(string $data[, string $logged = null ]) : bool

See '6. Binary Packet Protocol' of rfc4253 for more info.

Parameters
$data : string
$logged : string = null
Tags
see
self::_get_binary_packet()
access

private

Return values
bool

_send_channel_packet()

Sends channel data

public _send_channel_packet(int $client_channel, string $data) : bool

Spans multiple SSH_MSG_CHANNEL_DATAs if appropriate

Parameters
$client_channel : int
$data : string
Tags
access

private

Return values
bool

_send_sftp_packet()

Sends SFTP Packets

public _send_sftp_packet(int $type, string $data[, mixed $request_id = 1 ]) : bool

See '6. General Packet Format' of draft-ietf-secsh-filexfer-13 for more info.

Parameters
$type : int
$data : string
$request_id : mixed = 1
Tags
see
self::_get_sftp_packet()
see
self::_send_channel_packet()
access

private

Return values
bool

_setstat()

Sets information about a file

public _setstat(string $filename, string $attr, bool $recursive) : bool
Parameters
$filename : string
$attr : string
$recursive : bool
Tags
access

private

Return values
bool

_setstat_recursive()

Recursively sets information on directories on the SFTP server

public _setstat_recursive(string $path, string $attr, int &$i) : bool

Minimizes directory lookups and SSH_FXP_STATUS requests for speed.

Parameters
$path : string
$attr : string
$i : int
Tags
access

private

Return values
bool

_ssh_agent_login()

Login with an ssh-agent provided key

public _ssh_agent_login(string $username, Agent $agent) : bool
Parameters
$username : string
$agent : Agent
Tags
access

private

Return values
bool

_stat()

Returns general information about a file or symbolic link

public _stat(string $filename, int $type) : mixed

Determines information without calling \phpseclib\Net\SFTP::realpath(). The second parameter can be either NET_SFTP_STAT or NET_SFTP_LSTAT.

Parameters
$filename : string
$type : int
Tags
access

private

Return values
mixed

_string_shift()

String Shift

public _string_shift(string &$string[, int $index = 1 ]) : string

Inspired by array_shift

Parameters
$string : string
$index : int = 1
Tags
access

private

Return values
string

_update_stat_cache()

Save files / directories to cache

public _update_stat_cache(string $path, mixed $value) : mixed
Parameters
$path : string
$value : mixed
Tags
access

private

Return values
mixed

_updateLogHistory()

Update packet types in log history

public _updateLogHistory(string $old, string $new) : mixed
Parameters
$old : string
$new : string
Tags
access

private

Return values
mixed

chdir()

Changes the current directory

public chdir(string $dir) : bool
Parameters
$dir : string
Tags
access

public

Return values
bool

chgrp()

Changes file or directory group

public chgrp(string $filename, int $gid[, bool $recursive = false ]) : bool

Returns true on success or false on error.

Parameters
$filename : string
$gid : int
$recursive : bool = false
Tags
access

public

Return values
bool

chmod()

Set permissions on a file.

public chmod(int $mode, string $filename[, bool $recursive = false ]) : mixed

Returns the new file permissions on success or false on error. If $recursive is true than this just returns true or false.

Parameters
$mode : int
$filename : string
$recursive : bool = false
Tags
access

public

Return values
mixed

chown()

Changes file or directory owner

public chown(string $filename, int $uid[, bool $recursive = false ]) : bool

Returns true on success or false on error.

Parameters
$filename : string
$uid : int
$recursive : bool = false
Tags
access

public

Return values
bool

clearStatCache()

Clear the stat cache

public clearStatCache() : mixed
Tags
access

public

Return values
mixed

delete()

Deletes a file on the SFTP server.

public delete(string $path[, bool $recursive = true ]) : bool
Parameters
$path : string
$recursive : bool = true
Tags
access

public

Return values
bool

disableDatePreservation()

Disable Date Preservation

public disableDatePreservation() : mixed
Tags
access

public

Return values
mixed

disablePathCanonicalization()

Enable path canonicalization

public disablePathCanonicalization() : mixed
Tags
access

public

Return values
mixed

disablePTY()

Disable request-pty when using exec()

public disablePTY() : mixed
Tags
access

public

Return values
mixed

disableQuietMode()

Disable Quiet Mode

public disableQuietMode() : mixed

Show stderr in output

Tags
access

public

Return values
mixed

disableStatCache()

Disable the stat cache

public disableStatCache() : mixed
Tags
access

public

Return values
mixed

disconnect()

Disconnect

public disconnect() : mixed
Tags
access

public

Return values
mixed

enableDatePreservation()

Enable Date Preservation

public enableDatePreservation() : mixed
Tags
access

public

Return values
mixed

enablePathCanonicalization()

Enable path canonicalization

public enablePathCanonicalization() : mixed
Tags
access

public

Return values
mixed

enablePTY()

Enable request-pty when using exec()

public enablePTY() : mixed
Tags
access

public

Return values
mixed

enableQuietMode()

Enable Quiet Mode

public enableQuietMode() : mixed

Suppress stderr from output

Tags
access

public

Return values
mixed

enableStatCache()

Enable the stat cache

public enableStatCache() : mixed
Tags
access

public

Return values
mixed

exec()

Execute Command

public exec(string $command[, callable $callback = null ]) : string

If $callback is set to false then \phpseclib\Net\SSH2::_get_channel_packet(self::CHANNEL_EXEC) will need to be called manually. In all likelihood, this is not a feature you want to be taking advantage of.

Parameters
$command : string
$callback : callable = null
Tags
access

public

Return values
string

file_exists()

Checks whether a file or directory exists

public file_exists(string $path) : bool
Parameters
$path : string
Tags
access

public

Return values
bool

fileatime()

Gets last access time of file

public fileatime(string $path) : mixed
Parameters
$path : string
Tags
access

public

Return values
mixed

filegroup()

Gets file group

public filegroup(string $path) : mixed
Parameters
$path : string
Tags
access

public

Return values
mixed

filemtime()

Gets file modification time

public filemtime(string $path) : mixed
Parameters
$path : string
Tags
access

public

Return values
mixed

fileowner()

Gets file owner

public fileowner(string $path) : mixed
Parameters
$path : string
Tags
access

public

Return values
mixed

fileperms()

Gets file permissions

public fileperms(string $path) : mixed
Parameters
$path : string
Tags
access

public

Return values
mixed

filesize()

Gets file size

public filesize(string $path) : mixed
Parameters
$path : string
Tags
access

public

Return values
mixed

filetype()

Gets file type

public filetype(string $path) : mixed
Parameters
$path : string
Tags
access

public

Return values
mixed

get()

Downloads a file from the SFTP server.

public get(string $remote_file[, string $local_file = false ], int $offset[, int $length = -1 ][, callable|null $progressCallback = null ]) : mixed

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.

Parameters
$remote_file : string
$local_file : string = false
$offset : int
$length : int = -1
$progressCallback : callable|null = null
Tags
access

public

Return values
mixed

getAlgorithmsNegotiated()

Return list of negotiated algorithms

public getAlgorithmsNegotiated() : array<string|int, mixed>

Uses the same format as https://www.php.net/ssh2-methods-negotiated

Tags
access

public

Return values
array<string|int, mixed>

getBannerMessage()

Returns the banner message.

public getBannerMessage() : string

Quoting from the RFC, "in some jurisdictions, sending a warning message before authentication may be relevant for getting legal protection."

Tags
access

public

Return values
string

getCompressionAlgorithmsClient2Server()

Return a list of the compression algorithms the server supports, when receiving stuff from the client.

public getCompressionAlgorithmsClient2Server() : array<string|int, mixed>
Tags
access

public

Return values
array<string|int, mixed>

getCompressionAlgorithmsServer2Client()

Return a list of the compression algorithms the server supports, when sending stuff to the client.

public getCompressionAlgorithmsServer2Client() : array<string|int, mixed>
Tags
access

public

Return values
array<string|int, mixed>

getEncryptionAlgorithmsClient2Server()

Return a list of the (symmetric key) encryption algorithms the server supports, when receiving stuff from the client.

public getEncryptionAlgorithmsClient2Server() : array<string|int, mixed>
Tags
access

public

Return values
array<string|int, mixed>

getEncryptionAlgorithmsServer2Client()

Return a list of the (symmetric key) encryption algorithms the server supports, when sending stuff to the client.

public getEncryptionAlgorithmsServer2Client() : array<string|int, mixed>
Tags
access

public

Return values
array<string|int, mixed>

getErrors()

Returns all errors

public getErrors() : array<string|int, string>
Tags
access

public

Return values
array<string|int, string>

getExitStatus()

Returns the exit status of an SSH command or false.

public getExitStatus() : false|int
Tags
access

public

Return values
false|int

getKexAlgorithms()

Return a list of the key exchange algorithms the server supports.

public getKexAlgorithms() : array<string|int, mixed>
Tags
access

public

Return values
array<string|int, mixed>

getLanguagesClient2Server()

Return a list of the languages the server supports, when receiving stuff from the client.

public getLanguagesClient2Server() : array<string|int, mixed>
Tags
access

public

Return values
array<string|int, mixed>

getLanguagesServer2Client()

Return a list of the languages the server supports, when sending stuff to the client.

public getLanguagesServer2Client() : array<string|int, mixed>
Tags
access

public

Return values
array<string|int, mixed>

getLastError()

Returns the last error

public getLastError() : string
Tags
access

public

Return values
string

getLastSFTPError()

Returns the last error

public getLastSFTPError() : string
Tags
access

public

Return values
string

getLog()

Returns a log of the packets that have been sent and received.

public getLog() : array<string|int, mixed>|false|string

Returns a string if NET_SSH2_LOGGING == self::LOG_COMPLEX, an array if NET_SSH2_LOGGING == self::LOG_SIMPLE and false if !defined('NET_SSH2_LOGGING')

Tags
access

public

Return values
array<string|int, mixed>|false|string

getMACAlgorithmsClient2Server()

Return a list of the MAC algorithms the server supports, when receiving stuff from the client.

public getMACAlgorithmsClient2Server() : array<string|int, mixed>
Tags
access

public

Return values
array<string|int, mixed>

getMACAlgorithmsServer2Client()

Return a list of the MAC algorithms the server supports, when sending stuff to the client.

public getMACAlgorithmsServer2Client() : array<string|int, mixed>
Tags
access

public

Return values
array<string|int, mixed>

getServerAlgorithms()

Returns a list of algorithms the server supports

public getServerAlgorithms() : array<string|int, mixed>
Tags
access

public

Return values
array<string|int, mixed>

getServerHostKeyAlgorithms()

Return a list of the host key (public key) algorithms the server supports.

public getServerHostKeyAlgorithms() : array<string|int, mixed>
Tags
access

public

Return values
array<string|int, mixed>

getServerIdentification()

Return the server identification.

public getServerIdentification() : string
Tags
access

public

Return values
string

getServerPublicHostKey()

Returns the server public host key.

public getServerPublicHostKey() : mixed

Caching this the first time you connect to a server and checking the result on subsequent connections is recommended. Returns false if the server signature is not signed correctly with the public host key.

Tags
access

public

Return values
mixed

getSFTPErrors()

Returns all errors

public getSFTPErrors() : array<string|int, mixed>
Tags
access

public

Return values
array<string|int, mixed>

getSFTPLog()

Returns a log of the packets that have been sent and received.

public getSFTPLog() : string

Returns a string if NET_SFTP_LOGGING == NET_SFTP_LOG_COMPLEX, an array if NET_SFTP_LOGGING == NET_SFTP_LOG_SIMPLE and false if !defined('NET_SFTP_LOGGING')

Tags
access

public

Return values
string

or Array

getStdError()

Get the output from stdError

public getStdError() : mixed
Tags
access

public

Return values
mixed

getSupportedCompressionAlgorithms()

Returns a list of compression algorithms that phpseclib supports

public getSupportedCompressionAlgorithms() : array<string|int, mixed>
Tags
access

public

Return values
array<string|int, mixed>

getSupportedEncryptionAlgorithms()

Returns a list of symmetric key algorithms that phpseclib supports

public getSupportedEncryptionAlgorithms() : array<string|int, mixed>
Tags
access

public

Return values
array<string|int, mixed>

getSupportedHostKeyAlgorithms()

Returns a list of host key algorithms that phpseclib supports

public getSupportedHostKeyAlgorithms() : array<string|int, mixed>
Tags
access

public

Return values
array<string|int, mixed>

getSupportedKEXAlgorithms()

Returns a list of KEX algorithms that phpseclib supports

public getSupportedKEXAlgorithms() : array<string|int, mixed>
Tags
access

public

Return values
array<string|int, mixed>

getSupportedMACAlgorithms()

Returns a list of MAC algorithms that phpseclib supports

public getSupportedMACAlgorithms() : array<string|int, mixed>
Tags
access

public

Return values
array<string|int, mixed>

getSupportedVersions()

Get supported SFTP versions

public getSupportedVersions() : array<string|int, mixed>
Tags
access

public

Return values
array<string|int, mixed>

getWindowColumns()

Returns the number of columns for the terminal window size.

public getWindowColumns() : int
Tags
access

public

Return values
int

getWindowRows()

Returns the number of rows for the terminal window size.

public getWindowRows() : int
Tags
access

public

Return values
int

is_dir()

Tells whether the filename is a directory

public is_dir(string $path) : bool
Parameters
$path : string
Tags
access

public

Return values
bool

is_file()

Tells whether the filename is a regular file

public is_file(string $path) : bool
Parameters
$path : string
Tags
access

public

Return values
bool

Tells whether the filename is a symbolic link

public is_link(string $path) : bool
Parameters
$path : string
Tags
access

public

Return values
bool

is_readable()

Tells whether a file exists and is readable

public is_readable(string $path) : bool
Parameters
$path : string
Tags
access

public

Return values
bool

is_writable()

Tells whether the filename is writable

public is_writable(string $path) : bool
Parameters
$path : string
Tags
access

public

Return values
bool

is_writeable()

Tells whether the filename is writeable

public is_writeable(string $path) : bool

Alias of is_writable

Parameters
$path : string
Tags
access

public

Return values
bool

isAuthenticated()

Have you successfully been logged in?

public isAuthenticated() : bool
Tags
access

public

Return values
bool

isConnected()

Is the connection still active?

public isConnected() : bool
Tags
access

public

Return values
bool

isPTYEnabled()

Returns whether request-pty is enabled or not

public isPTYEnabled() : bool
Tags
see
self::enablePTY()
see
self::disablePTY()
access

public

Return values
bool

isQuietModeEnabled()

Returns whether Quiet Mode is enabled or not

public isQuietModeEnabled() : bool
Tags
see
self::enableQuietMode()
see
self::disableQuietMode()
access

public

Return values
bool

isTimeout()

Is timeout?

public isTimeout() : mixed

Did exec() or read() return because they timed out or because they encountered the end?

Tags
access

public

Return values
mixed

login()

Login

public login(string $username) : bool
Parameters
$username : string
Tags
access

public

Return values
bool

lstat()

Returns general information about a file or symbolic link.

public lstat(string $filename) : mixed

Returns an array on success and false otherwise.

Parameters
$filename : string
Tags
access

public

Return values
mixed

mkdir()

Creates a directory.

public mkdir(string $dir[, mixed $mode = -1 ][, mixed $recursive = false ]) : bool
Parameters
$dir : string
$mode : mixed = -1
$recursive : mixed = false
Tags
access

public

Return values
bool

nlist()

Returns a list of files in the given directory

public nlist([string $dir = '.' ][, bool $recursive = false ]) : mixed
Parameters
$dir : string = '.'
$recursive : bool = false
Tags
access

public

Return values
mixed

ping()

Pings a server connection, or tries to reconnect if the connection has gone down

public ping() : bool

Inspired by http://php.net/manual/en/mysqli.ping.php

Tags
access

public

Return values
bool

pwd()

Returns the current directory name

public pwd() : mixed
Tags
access

public

Return values
mixed

rawlist()

Returns a detailed list of files in the given directory

public rawlist([string $dir = '.' ][, bool $recursive = false ]) : mixed
Parameters
$dir : string = '.'
$recursive : bool = false
Tags
access

public

Return values
mixed

read()

Returns the output of an interactive shell

public read([string $expect = '' ][, int $mode = self::READ_SIMPLE ]) : string|bool

Returns when there's a match for $expect, which can take the form of a string literal or, if $mode == self::READ_REGEX, a regular expression.

Parameters
$expect : string = ''
$mode : int = self::READ_SIMPLE
Tags
see
self::write()
access

public

Return values
string|bool

Return the target of a symbolic link

public readlink(string $link) : mixed
Parameters
$link : string
Tags
access

public

Return values
mixed

realpath()

Returns canonicalized absolute pathname

public realpath(string $path) : mixed

realpath() expands all symbolic links and resolves references to '/./', '/../' and extra '/' characters in the input path and returns the canonicalized absolute pathname.

Parameters
$path : string
Tags
access

public

Return values
mixed

rename()

Renames a file or a directory on the SFTP server

public rename(string $oldname, string $newname) : bool
Parameters
$oldname : string
$newname : string
Tags
access

public

Return values
bool

reset()

Closes a channel

public reset() : mixed

If read() timed out you might want to just close the channel and have it auto-restart on the next read() call

Tags
access

public

Return values
mixed

rmdir()

Removes a directory.

public rmdir(string $dir) : bool
Parameters
$dir : string
Tags
access

public

Return values
bool

sendIdentificationStringFirst()

Send Identification String First

public sendIdentificationStringFirst() : mixed

https://tools.ietf.org/html/rfc4253#section-4.2 says "when the connection has been established, both sides MUST send an identification string". It does not say which side sends it first. In theory it shouldn't matter but it is a fact of life that some SSH servers are simply buggy

Tags
access

public

Return values
mixed

sendIdentificationStringLast()

Send Identification String Last

public sendIdentificationStringLast() : mixed

https://tools.ietf.org/html/rfc4253#section-4.2 says "when the connection has been established, both sides MUST send an identification string". It does not say which side sends it first. In theory it shouldn't matter but it is a fact of life that some SSH servers are simply buggy

Tags
access

public

Return values
mixed

sendKEXINITFirst()

Send SSH_MSG_KEXINIT First

public sendKEXINITFirst() : mixed

https://tools.ietf.org/html/rfc4253#section-7.1 says "key exchange begins by each sending sending the [SSH_MSG_KEXINIT] packet". It does not say which side sends it first. In theory it shouldn't matter but it is a fact of life that some SSH servers are simply buggy

Tags
access

public

Return values
mixed

sendKEXINITLast()

Send SSH_MSG_KEXINIT Last

public sendKEXINITLast() : mixed

https://tools.ietf.org/html/rfc4253#section-7.1 says "key exchange begins by each sending sending the [SSH_MSG_KEXINIT] packet". It does not say which side sends it first. In theory it shouldn't matter but it is a fact of life that some SSH servers are simply buggy

Tags
access

public

Return values
mixed

setCryptoEngine()

Set Crypto Engine Mode

public setCryptoEngine(int $engine) : mixed

Possible $engine values: CRYPT_MODE_INTERNAL, CRYPT_MODE_MCRYPT

Parameters
$engine : int
Tags
access

public

Return values
mixed

setListOrder()

Defines how nlist() and rawlist() will be sorted - if at all.

public setListOrder() : mixed

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

Tags
access

public

Return values
mixed

setPreferredAlgorithms()

Accepts an associative array with up to four parameters as described at <https://www.php.net/manual/en/function.ssh2-connect.php>

public setPreferredAlgorithms(array<string|int, mixed> $methods) : mixed
Parameters
$methods : array<string|int, mixed>
Tags
access

public

Return values
mixed

setTimeout()

Set Timeout

public setTimeout(mixed $timeout) : mixed

$ssh->exec('ping 127.0.0.1'); on a Linux host will never return and will run indefinitely. setTimeout() makes it so it'll timeout. Setting $timeout to false or 0 will mean there is no timeout.

Parameters
$timeout : mixed
Tags
access

public

Return values
mixed

setWindowColumns()

Sets the number of columns for the terminal window size.

public setWindowColumns(int $value) : mixed
Parameters
$value : int
Tags
access

public

Return values
mixed

setWindowRows()

Sets the number of rows for the terminal window size.

public setWindowRows(int $value) : mixed
Parameters
$value : int
Tags
access

public

Return values
mixed

setWindowSize()

Sets the number of columns and rows for the terminal window size.

public setWindowSize([int $columns = 80 ][, int $rows = 24 ]) : mixed
Parameters
$columns : int = 80
$rows : int = 24
Tags
access

public

Return values
mixed

size()

Returns the file size, in bytes, or false, on failure

public size(string $filename) : mixed

Files larger than 4GB will show up as being exactly 4GB.

Parameters
$filename : string
Tags
access

public

Return values
mixed

startSubsystem()

Start a subsystem.

public startSubsystem(string $subsystem) : bool

Right now only one subsystem at a time is supported. To support multiple subsystem's stopSubsystem() could accept a string that contained the name of the subsystem, but at that point, only one subsystem of each type could be opened. To support multiple subsystem's of the same name maybe it'd be best if startSubsystem() generated a new channel id and returns that and then that that was passed into stopSubsystem() but that'll be saved for a future date and implemented if there's sufficient demand for such a feature.

Parameters
$subsystem : string
Tags
see
self::stopSubsystem()
access

public

Return values
bool

stat()

Returns general information about a file.

public stat(string $filename) : mixed

Returns an array on success and false otherwise.

Parameters
$filename : string
Tags
access

public

Return values
mixed

stopSubsystem()

Stops a subsystem.

public stopSubsystem() : bool
Tags
see
self::startSubsystem()
access

public

Return values
bool

Create a symlink

public symlink(string $target, string $link) : bool

symlink() creates a symbolic link to the existing target with the specified name link.

Parameters
$target : string
$link : string
Tags
access

public

Return values
bool

touch()

Sets access and modification time of file.

public touch(string $filename[, int $time = null ][, int $atime = null ]) : bool

If the file does not exist, it will be created.

Parameters
$filename : string
$time : int = null
$atime : int = null
Tags
access

public

Return values
bool

truncate()

Truncates a file to a given length

public truncate(string $filename, int $new_size) : bool
Parameters
$filename : string
$new_size : int
Tags
access

public

Return values
bool

write()

Inputs a command into an interactive shell.

public write(string $cmd) : bool
Parameters
$cmd : string
Tags
see
self::read()
access

public

Return values
bool

Search results