\phpseclib\NetSFTP

Pure-PHP implementations of SFTP.

Summary

Methods
Properties
Constants
__construct()
setCryptoEngine()
sendIdentificationStringFirst()
sendIdentificationStringLast()
sendKEXINITFirst()
sendKEXINITLast()
_connect()
_generate_identifier()
_key_exchange()
_encryption_algorithm_to_key_size()
_encryption_algorithm_to_crypt_instance()
_bad_algorithm_candidate()
login()
_login()
_keyboard_interactive_login()
_keyboard_interactive_process()
_ssh_agent_login()
setTimeout()
getStdError()
exec()
_initShell()
_get_interactive_channel()
_get_open_channel()
read()
write()
startSubsystem()
stopSubsystem()
reset()
isTimeout()
disconnect()
__destruct()
isConnected()
isAuthenticated()
ping()
_reconnect()
_reset_connection()
_get_binary_packet()
_filter()
enableQuietMode()
disableQuietMode()
isQuietModeEnabled()
enablePTY()
disablePTY()
isPTYEnabled()
_get_channel_packet()
_send_binary_packet()
_append_log()
_send_channel_packet()
_close_channel()
_disconnect()
_string_shift()
_define_array()
getLog()
_format_log()
_format_log_helper()
_on_channel_open()
_array_intersect_first()
getErrors()
getLastError()
getServerIdentification()
getKexAlgorithms()
getServerHostKeyAlgorithms()
getEncryptionAlgorithmsClient2Server()
getEncryptionAlgorithmsServer2Client()
getMACAlgorithmsClient2Server()
getMACAlgorithmsServer2Client()
getCompressionAlgorithmsClient2Server()
getCompressionAlgorithmsServer2Client()
getLanguagesServer2Client()
getLanguagesClient2Server()
getBannerMessage()
getServerPublicHostKey()
getExitStatus()
getWindowColumns()
getWindowRows()
setWindowColumns()
setWindowRows()
setWindowSize()
disableStatCache()
enableStatCache()
clearStatCache()
enablePathCanonicalization()
disablePathCanonicalization()
pwd()
_logError()
realpath()
_realpath()
chdir()
nlist()
_nlist_helper()
rawlist()
_list()
_comparator()
setListOrder()
size()
_update_stat_cache()
_remove_from_stat_cache()
_query_stat_cache()
stat()
lstat()
_stat()
truncate()
touch()
chown()
chgrp()
chmod()
_setstat()
_setstat_recursive()
readlink()
symlink()
mkdir()
_mkdir_helper()
rmdir()
_read_put_responses()
_close_handle()
get()
delete()
_delete_recursive()
file_exists()
is_dir()
is_file()
is_link()
is_readable()
is_writable()
is_writeable()
fileatime()
filemtime()
fileperms()
fileowner()
filegroup()
filesize()
filetype()
_get_stat_cache_prop()
_get_lstat_cache_prop()
_get_xstat_cache_prop()
rename()
_parseAttributes()
_parseMode()
_parseLongname()
_send_sftp_packet()
_get_sftp_packet()
getSFTPLog()
getSFTPErrors()
getLastSFTPError()
getSupportedVersions()
$identifier
$fsock
$bitmap
$errors
$server_identifier
$kex_algorithms
$kex_dh_group_size_min
$kex_dh_group_size_preferred
$kex_dh_group_size_max
$server_host_key_algorithms
$encryption_algorithms_client_to_server
$encryption_algorithms_server_to_client
$mac_algorithms_client_to_server
$mac_algorithms_server_to_client
$compression_algorithms_client_to_server
$compression_algorithms_server_to_client
$languages_server_to_client
$languages_client_to_server
$encrypt_block_size
$decrypt_block_size
$decrypt
$encrypt
$hmac_create
$hmac_check
$hmac_size
$server_public_host_key
$session_id
$exchange_hash
$message_numbers
$disconnect_reasons
$channel_open_failure_reasons
$terminal_modes
$channel_extended_data_type_codes
$send_seq_no
$get_seq_no
$server_channels
$channel_buffers
$channel_status
$packet_size_client_to_server
$message_number_log
$message_log
$window_size
$window_size_server_to_client
$window_size_client_to_server
$signature
$signature_format
$interactiveBuffer
$log_size
$timeout
$curTimeout
$realtime_log_file
$realtime_log_size
$signature_validated
$realtime_log_wrap
$quiet_mode
$last_packet
$exit_status
$request_pty
$in_request_pty_exec
$in_subsystem
$stdErrorLog
$last_interactive_response
$keyboard_requests_responses
$banner_message
$is_timeout
$log_boundary
$log_long_width
$log_short_width
$host
$port
$windowColumns
$windowRows
$crypto_engine
$agent
$send_id_string_first
$send_kex_first
$bad_key_size_fix
$decrypt_algorithm
$retry_connect
$binary_packet_buffer
$preferred_signature_format
$auth
$packet_types
$status_codes
$use_request_id
$packet_type
$packet_buffer
$extensions
$version
$pwd
$packet_type_log
$packet_log
$sftp_errors
$stat_cache
$max_sftp_packet
$use_stat_cache
$sortOptions
$canonicalize_paths
$requestBuffer
MASK_CONSTRUCTOR
MASK_CONNECTED
MASK_LOGIN_REQ
MASK_LOGIN
MASK_SHELL
MASK_WINDOW_ADJUST
CHANNEL_EXEC
CHANNEL_SHELL
CHANNEL_SUBSYSTEM
CHANNEL_AGENT_FORWARD
CHANNEL_KEEP_ALIVE
LOG_SIMPLE
LOG_COMPLEX
LOG_REALTIME
LOG_REALTIME_FILE
LOG_MAX_SIZE
READ_SIMPLE
READ_REGEX
READ_NEXT
CHANNEL
SOURCE_LOCAL_FILE
SOURCE_STRING
SOURCE_CALLBACK
RESUME
RESUME_START
No protected methods found
No protected properties found
N/A
No private methods found
No private properties found
N/A

Constants

MASK_CONSTRUCTOR

MASK_CONSTRUCTOR

MASK_CONNECTED

MASK_CONNECTED

MASK_LOGIN_REQ

MASK_LOGIN_REQ

MASK_LOGIN

MASK_LOGIN

MASK_SHELL

MASK_SHELL

MASK_WINDOW_ADJUST

MASK_WINDOW_ADJUST

CHANNEL_EXEC

CHANNEL_EXEC

CHANNEL_SHELL

CHANNEL_SHELL

CHANNEL_SUBSYSTEM

CHANNEL_SUBSYSTEM

CHANNEL_AGENT_FORWARD

CHANNEL_AGENT_FORWARD

CHANNEL_KEEP_ALIVE

CHANNEL_KEEP_ALIVE

LOG_SIMPLE

LOG_SIMPLE

Returns the message numbers

LOG_COMPLEX

LOG_COMPLEX

Returns the message content

LOG_REALTIME

LOG_REALTIME

Outputs the content real-time

LOG_REALTIME_FILE

LOG_REALTIME_FILE

Dumps the content real-time to a file

LOG_MAX_SIZE

LOG_MAX_SIZE

Make sure that the log never gets larger than this

READ_SIMPLE

READ_SIMPLE

Returns when a string matching $expect exactly is found

READ_REGEX

READ_REGEX

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

READ_NEXT

READ_NEXT

Returns whenever a data packet is received.

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

CHANNEL

CHANNEL

SFTP channel constant

\phpseclib\Net\SSH2::exec() uses 0 and \phpseclib\Net\SSH2::read() / \phpseclib\Net\SSH2::write() use 1.

SOURCE_LOCAL_FILE

SOURCE_LOCAL_FILE

Reads data from a local file.

SOURCE_STRING

SOURCE_STRING

SOURCE_CALLBACK

SOURCE_CALLBACK

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

RESUME

RESUME

Resumes an upload

RESUME_START

RESUME_START

Append a local file to an already existing remote file

Properties

$identifier

$identifier : string

The SSH identifier

Type

string

$fsock

$fsock : object

The Socket Object

Type

object

$bitmap

$bitmap : integer

Execution Bitmap

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.

Type

integer

$errors

$errors : string

Error information

Type

string

$server_identifier

$server_identifier : array|false

Server Identifier

Type

array|false

$kex_algorithms

$kex_algorithms : array|false

Key Exchange Algorithms

Type

array|false

$kex_dh_group_size_min

$kex_dh_group_size_min : integer

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

Type

integer

$kex_dh_group_size_preferred

$kex_dh_group_size_preferred : integer

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

Type

integer

$kex_dh_group_size_max

$kex_dh_group_size_max : integer

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

Type

integer

$server_host_key_algorithms

$server_host_key_algorithms : array|false

Server Host Key Algorithms

Type

array|false

$encryption_algorithms_client_to_server

$encryption_algorithms_client_to_server : array|false

Encryption Algorithms: Client to Server

Type

array|false

$encryption_algorithms_server_to_client

$encryption_algorithms_server_to_client : array|false

Encryption Algorithms: Server to Client

Type

array|false

$mac_algorithms_client_to_server

$mac_algorithms_client_to_server : array|false

MAC Algorithms: Client to Server

Type

array|false

$mac_algorithms_server_to_client

$mac_algorithms_server_to_client : array|false

MAC Algorithms: Server to Client

Type

array|false

$compression_algorithms_client_to_server

$compression_algorithms_client_to_server : array|false

Compression Algorithms: Client to Server

Type

array|false

$compression_algorithms_server_to_client

$compression_algorithms_server_to_client : array|false

Compression Algorithms: Server to Client

Type

array|false

$languages_server_to_client

$languages_server_to_client : array|false

Languages: Server to Client

Type

array|false

$languages_client_to_server

$languages_client_to_server : array|false

Languages: Client to Server

Type

array|false

$encrypt_block_size

$encrypt_block_size : integer

Block Size for Server to Client Encryption

"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

Type

integer

$decrypt_block_size

$decrypt_block_size : integer

Block Size for Client to Server Encryption

Type

integer

$decrypt

$decrypt : object

Server to Client Encryption Object

Type

object

$encrypt

$encrypt : object

Client to Server Encryption Object

Type

object

$hmac_create

$hmac_create : object

Client to Server HMAC Object

Type

object

$hmac_check

$hmac_check : object

Server to Client HMAC Object

Type

object

$hmac_size

$hmac_size : integer

Size of server to client HMAC

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.

Type

integer

$server_public_host_key

$server_public_host_key : string

Server Public Host Key

Type

string

$session_id

$session_id : string

Session identifier

"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

Type

string

$exchange_hash

$exchange_hash : string

Exchange hash

The current exchange hash

Type

string

$message_numbers

$message_numbers : array

Message Numbers

Type

array

$disconnect_reasons

$disconnect_reasons : array

Disconnection Message 'reason codes' defined in RFC4253

Type

array

$channel_open_failure_reasons

$channel_open_failure_reasons : array

SSH_MSG_CHANNEL_OPEN_FAILURE 'reason codes', defined in RFC4254

Type

array

$terminal_modes

$terminal_modes : array

Terminal Modes

Type

array

$channel_extended_data_type_codes

$channel_extended_data_type_codes : array

SSH_MSG_CHANNEL_EXTENDED_DATA's data_type_codes

Type

array

$send_seq_no

$send_seq_no : integer

Send Sequence Number

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

Type

integer

$get_seq_no

$get_seq_no : integer

Get Sequence Number

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

Type

integer

$server_channels

$server_channels : array

Server Channels

Maps client channels to server channels

Type

array

$channel_buffers

$channel_buffers : array

Channel Buffers

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

Type

array

$channel_status

$channel_status : array

Channel Status

Contains the type of the last sent message

Type

array

$packet_size_client_to_server

$packet_size_client_to_server : array

Packet Size

Maximum packet size indexed by channel

Type

array

$message_number_log

$message_number_log : array

Message Number Log

Type

array

$message_log

$message_log : array

Message Log

Type

array

$window_size

$window_size : integer

The Window Size

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

Type

integer

$window_size_server_to_client

$window_size_server_to_client : array

Window size, server to client

Window size indexed by channel

Type

array

$window_size_client_to_server

$window_size_client_to_server : array

Window size, client to server

Window size indexed by channel

Type

array

$signature

$signature : string

Server signature

Verified against $this->session_id

Type

string

$signature_format

$signature_format : string

Server signature format

ssh-rsa or ssh-dss.

Type

string

$interactiveBuffer

$interactiveBuffer : array

Interactive Buffer

Type

array

$log_size

$log_size : integer

Current log size

Should never exceed self::LOG_MAX_SIZE

Type

integer

$timeout

$timeout : 

Timeout

Type

$curTimeout

$curTimeout : 

Current Timeout

Type

$realtime_log_file

$realtime_log_file : resource

Real-time log file pointer

Type

resource

$realtime_log_size

$realtime_log_size : integer

Real-time log file size

Type

integer

$signature_validated

$signature_validated : boolean

Has the signature been validated?

Type

boolean

$realtime_log_wrap

$realtime_log_wrap : 

Real-time log file wrap boolean

Type

$quiet_mode

$quiet_mode : 

Flag to suppress stderr from output

Type

$last_packet

$last_packet : integer

Time of first network activity

Type

integer

$exit_status

$exit_status : integer

Exit status returned from ssh if any

Type

integer

$request_pty

$request_pty : boolean

Flag to request a PTY when using exec()

Type

boolean

$in_request_pty_exec

$in_request_pty_exec : boolean

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

Type

boolean

$in_subsystem

$in_subsystem : boolean

Flag set after startSubsystem() is called

Type

boolean

$stdErrorLog

$stdErrorLog : string

Contents of stdError

Type

string

$last_interactive_response

$last_interactive_response : string

The Last Interactive Response

Type

string

$keyboard_requests_responses

$keyboard_requests_responses : array

Keyboard Interactive Request / Responses

Type

array

$banner_message

$banner_message : string

Banner Message

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

Type

string

$is_timeout

$is_timeout : boolean

Did read() timeout or return normally?

Type

boolean

$log_boundary

$log_boundary : string

Log Boundary

Type

string

$log_long_width

$log_long_width : integer

Log Long Width

Type

integer

$log_short_width

$log_short_width : integer

Log Short Width

Type

integer

$host

$host : string

Hostname

Type

string

$port

$port : integer

Port Number

Type

integer

$windowColumns

$windowColumns : integer

Number of columns for terminal window size

Type

integer

$windowRows

$windowRows : integer

Number of columns for terminal window size

Type

integer

$crypto_engine

$crypto_engine : integer

Crypto Engine

Type

integer

$agent

$agent : \phpseclib\Net\System_SSH_Agent

A System_SSH_Agent for use in the SSH2 Agent Forwarding scenario

Type

\phpseclib\Net\System_SSH_Agent

$send_id_string_first

$send_id_string_first : boolean

Send the identification string first?

Type

boolean

$send_kex_first

$send_kex_first : boolean

Send the key exchange initiation packet first?

Type

boolean

$bad_key_size_fix

$bad_key_size_fix : boolean

Some versions of OpenSSH incorrectly calculate the key size

Type

boolean

$decrypt_algorithm

$decrypt_algorithm : string

The selected decryption algorithm

Type

string

$retry_connect

$retry_connect : boolean

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

Type

boolean

$binary_packet_buffer

$binary_packet_buffer : string|false

Binary Packet Buffer

Type

string|false

$preferred_signature_format

$preferred_signature_format : string|false

Preferred Signature Format

Type

string|false

$auth

$auth : array

Authentication Credentials

Type

array

$packet_types

$packet_types : array

Packet Types

Type

array

$status_codes

$status_codes : array

Status Codes

Type

array

$use_request_id

$use_request_id : boolean

The Request ID

The request ID exists in the off chance that a packet is sent out-of-order. Of course, this library doesn't support concurrent actions, so it's somewhat academic, here.

Type

boolean

$packet_type

$packet_type : integer

The Packet Type

The request ID exists in the off chance that a packet is sent out-of-order. Of course, this library doesn't support concurrent actions, so it's somewhat academic, here.

Type

integer

$packet_buffer

$packet_buffer : string

Packet Buffer

Type

string

$extensions

$extensions : array

Extensions supported by the server

Type

array

$version

$version : integer

Server SFTP version

Type

integer

$pwd

$pwd : string

Current working directory

Type

string

$packet_type_log

$packet_type_log : array

Packet Type Log

Type

array

$packet_log

$packet_log : array

Packet Log

Type

array

$sftp_errors

$sftp_errors : array

Error information

Type

array

$stat_cache

$stat_cache : array

Stat Cache

Rather than always having to open a directory and close it immediately there after to see if a file is a directory we'll cache the results.

Type

array

$max_sftp_packet

$max_sftp_packet : array

Max SFTP Packet Size

Type

array

$use_stat_cache

$use_stat_cache : boolean

Stat Cache Flag

Type

boolean

$sortOptions

$sortOptions : array

Sort Options

Type

array

$canonicalize_paths

$canonicalize_paths : boolean

Canonicalization Flag

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

Type

boolean

$requestBuffer

$requestBuffer : array

Request Buffers

Type

array

Methods

__construct()

__construct(string  $host, integer  $port = 22, integer  $timeout = 10) : \phpseclib\Net\SFTP

Default Constructor.

Connects to an SFTP server

Parameters

string $host
integer $port
integer $timeout

Returns

\phpseclib\Net\SFTP

setCryptoEngine()

setCryptoEngine(integer  $engine) 

Set Crypto Engine Mode

Possible $engine values: CRYPT_MODE_INTERNAL, CRYPT_MODE_MCRYPT

Parameters

integer $engine

sendIdentificationStringFirst()

sendIdentificationStringFirst() 

Send Identification String First

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

sendIdentificationStringLast()

sendIdentificationStringLast() 

Send Identification String Last

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

sendKEXINITFirst()

sendKEXINITFirst() 

Send SSH_MSG_KEXINIT First

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

sendKEXINITLast()

sendKEXINITLast() 

Send SSH_MSG_KEXINIT Last

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

_connect()

_connect() : boolean

Connect to an SSHv2 server

Returns

boolean

_generate_identifier()

_generate_identifier() : string

Generates the SSH identifier

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

Returns

string

_key_exchange()

_key_exchange(string  $kexinit_payload_server = false) 

Key Exchange

Parameters

string $kexinit_payload_server

optional

_encryption_algorithm_to_key_size()

_encryption_algorithm_to_key_size(string  $algorithm) : integer|null

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

Parameters

string $algorithm

Name of the encryption algorithm

Returns

integer|null —

Number of bytes as an integer or null for unknown

_encryption_algorithm_to_crypt_instance()

_encryption_algorithm_to_crypt_instance(string  $algorithm) : mixed

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

Parameters

string $algorithm

Name of the encryption algorithm

Returns

mixed —

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

_bad_algorithm_candidate()

_bad_algorithm_candidate(  $algorithm) 

Parameters

$algorithm

login()

login(string  $username) : boolean

Login

The $password parameter can be a plaintext password, a \phpseclib\Crypt\RSA object or an array

Parameters

string $username

Returns

boolean

_login()

_login(string  $username) : boolean

Login Helper

Parameters

string $username

Returns

boolean

_keyboard_interactive_login()

_keyboard_interactive_login(string  $username, string  $password) : boolean

Login via keyboard-interactive authentication

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

Parameters

string $username
string $password

Returns

boolean

_keyboard_interactive_process()

_keyboard_interactive_process() : boolean

Handle the keyboard-interactive requests / responses.

Returns

boolean

_ssh_agent_login()

_ssh_agent_login(string  $username, \phpseclib\System\SSH\Agent  $agent) : boolean

Login with an ssh-agent provided key

Parameters

string $username
\phpseclib\System\SSH\Agent $agent

Returns

boolean

setTimeout()

setTimeout(mixed  $timeout) 

Set Timeout

$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

mixed $timeout

getStdError()

getStdError() 

Get the output from stdError

exec()

exec(string  $command, Callback  $callback = null) : string

Execute Command

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

string $command
Callback $callback

Returns

string

_initShell()

_initShell() : boolean

Creates an interactive shell

Returns

boolean

_get_interactive_channel()

_get_interactive_channel() : integer

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

Returns

integer

_get_open_channel()

_get_open_channel() : integer

Return an available open channel

Returns

integer

read()

read(string  $expect = '', integer  $mode = self::READ_SIMPLE) : string

Returns the output of an interactive shell

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

string $expect
integer $mode

Returns

string

write()

write(string  $cmd) : boolean

Inputs a command into an interactive shell.

Parameters

string $cmd

Returns

boolean

startSubsystem()

startSubsystem(string  $subsystem) : boolean

Start a subsystem.

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

string $subsystem

Returns

boolean

stopSubsystem()

stopSubsystem() : boolean

Stops a subsystem.

Returns

boolean

reset()

reset() 

Closes a channel

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

isTimeout()

isTimeout() 

Is timeout?

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

disconnect()

disconnect() 

Disconnect

__destruct()

__destruct() 

Destructor.

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

isConnected()

isConnected() : boolean

Is the connection still active?

Returns

boolean

isAuthenticated()

isAuthenticated() : boolean

Have you successfully been logged in?

Returns

boolean

_reconnect()

_reconnect() : boolean

In situ reconnect method

Returns

boolean

_reset_connection()

_reset_connection(integer  $reason) 

Resets a connection for re-use

Parameters

integer $reason

_get_binary_packet()

_get_binary_packet(  $skip_channel_filter = false) : string

Gets Binary Packets

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

Parameters

$skip_channel_filter

Returns

string

_filter()

_filter(  $payload,   $skip_channel_filter) : string

Filter Binary Packets

Because some binary packets need to be ignored...

Parameters

$payload
$skip_channel_filter

Returns

string

enableQuietMode()

enableQuietMode() 

Enable Quiet Mode

Suppress stderr from output

disableQuietMode()

disableQuietMode() 

Disable Quiet Mode

Show stderr in output

isQuietModeEnabled()

isQuietModeEnabled() : boolean

Returns whether Quiet Mode is enabled or not

Returns

boolean

enablePTY()

enablePTY() 

Enable request-pty when using exec()

disablePTY()

disablePTY() 

Disable request-pty when using exec()

isPTYEnabled()

isPTYEnabled() : boolean

Returns whether request-pty is enabled or not

Returns

boolean

_get_channel_packet()

_get_channel_packet(  $client_channel,   $skip_extended = false) : mixed

Gets channel data

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

Parameters

$client_channel
$skip_extended

Returns

mixed

_send_binary_packet()

_send_binary_packet(string  $data, string  $logged = null) : boolean

Sends Binary Packets

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

Parameters

string $data
string $logged

Returns

boolean

_append_log()

_append_log(  $message_number,   $message) 

Logs data packets

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

Parameters

$message_number
$message

_send_channel_packet()

_send_channel_packet(integer  $client_channel, string  $data) : boolean

Sends channel data

Spans multiple SSH_MSG_CHANNEL_DATAs if appropriate

Parameters

integer $client_channel
string $data

Returns

boolean

_close_channel()

_close_channel(integer  $client_channel, boolean  $want_reply = false) : boolean

Closes and flushes a channel

\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

integer $client_channel
boolean $want_reply

Returns

boolean

_disconnect()

_disconnect(integer  $reason) : boolean

Disconnect

Parameters

integer $reason

Returns

boolean

_string_shift()

_string_shift(string  $string, integer  $index = 1) : string

String Shift

Inspired by array_shift

Parameters

string $string
integer $index

Returns

string

_define_array()

_define_array() 

Define Array

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.

getLog()

getLog() : array|false|string

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

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')

Returns

array|false|string

_format_log()

_format_log(array  $message_log, array  $message_number_log) : string

Formats a log for printing

Parameters

array $message_log
array $message_number_log

Returns

string

_format_log_helper()

_format_log_helper(array  $matches) : string

Helper function for _format_log

For use with preg_replace_callback()

Parameters

array $matches

Returns

string

_on_channel_open()

_on_channel_open() 

Helper function for agent->_on_channel_open()

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

_array_intersect_first()

_array_intersect_first(array  $array1, array  $array2) : 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.

Parameters

array $array1
array $array2

Returns

mixed —

False if intersection is empty, else intersected value.

getErrors()

getErrors() : array<mixed,string>

Returns all errors

Returns

array<mixed,string>

getLastError()

getLastError() : string

Returns the last error

Returns

string

getServerIdentification()

getServerIdentification() : string

Return the server identification.

Returns

string

getKexAlgorithms()

getKexAlgorithms() : array

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

Returns

array

getServerHostKeyAlgorithms()

getServerHostKeyAlgorithms() : array

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

Returns

array

getEncryptionAlgorithmsClient2Server()

getEncryptionAlgorithmsClient2Server() : array

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

Returns

array

getEncryptionAlgorithmsServer2Client()

getEncryptionAlgorithmsServer2Client() : array

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

Returns

array

getMACAlgorithmsClient2Server()

getMACAlgorithmsClient2Server() : array

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

Returns

array

getMACAlgorithmsServer2Client()

getMACAlgorithmsServer2Client() : array

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

Returns

array

getCompressionAlgorithmsClient2Server()

getCompressionAlgorithmsClient2Server() : array

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

Returns

array

getCompressionAlgorithmsServer2Client()

getCompressionAlgorithmsServer2Client() : array

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

Returns

array

getLanguagesServer2Client()

getLanguagesServer2Client() : array

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

Returns

array

getLanguagesClient2Server()

getLanguagesClient2Server() : array

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

Returns

array

getBannerMessage()

getBannerMessage() : string

Returns the banner message.

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

Returns

string

getServerPublicHostKey()

getServerPublicHostKey() : mixed

Returns the server public host key.

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.

Returns

mixed

getExitStatus()

getExitStatus() : false|integer

Returns the exit status of an SSH command or false.

Returns

false|integer

getWindowColumns()

getWindowColumns() : integer

Returns the number of columns for the terminal window size.

Returns

integer

getWindowRows()

getWindowRows() : integer

Returns the number of rows for the terminal window size.

Returns

integer

setWindowColumns()

setWindowColumns(integer  $value) 

Sets the number of columns for the terminal window size.

Parameters

integer $value

setWindowRows()

setWindowRows(integer  $value) 

Sets the number of rows for the terminal window size.

Parameters

integer $value

setWindowSize()

setWindowSize(integer  $columns = 80, integer  $rows = 24) 

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

Parameters

integer $columns
integer $rows

disableStatCache()

disableStatCache() 

Disable the stat cache

enableStatCache()

enableStatCache() 

Enable the stat cache

clearStatCache()

clearStatCache() 

Clear the stat cache

enablePathCanonicalization()

enablePathCanonicalization() 

Enable path canonicalization

disablePathCanonicalization()

disablePathCanonicalization() 

Enable path canonicalization

pwd()

pwd() : mixed

Returns the current directory name

Returns

mixed

_logError()

_logError(string  $response, integer  $status = -1) 

Logs errors

Parameters

string $response
integer $status

realpath()

realpath(string  $path) : mixed

Returns canonicalized absolute pathname

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

Parameters

string $path

Returns

mixed

_realpath()

_realpath(string  $path) : mixed

Canonicalize the Server-Side Path Name

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

string $path

Returns

mixed

chdir()

chdir(string  $dir) : boolean

Changes the current directory

Parameters

string $dir

Returns

boolean

nlist()

nlist(string  $dir = '.', boolean  $recursive = false) : mixed

Returns a list of files in the given directory

Parameters

string $dir
boolean $recursive

Returns

mixed

_nlist_helper()

_nlist_helper(string  $dir, boolean  $recursive, string  $relativeDir) : mixed

Helper method for nlist

Parameters

string $dir
boolean $recursive
string $relativeDir

Returns

mixed

rawlist()

rawlist(string  $dir = '.', boolean  $recursive = false) : mixed

Returns a detailed list of files in the given directory

Parameters

string $dir
boolean $recursive

Returns

mixed

_list()

_list(string  $dir, boolean  $raw = true) : mixed

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

Parameters

string $dir
boolean $raw

Returns

mixed

_comparator()

_comparator(array  $a, array  $b) : integer

Compares two rawlist entries using parameters set by setListOrder()

Intended for use with uasort()

Parameters

array $a
array $b

Returns

integer

setListOrder()

setListOrder() 

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

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

size()

size(string  $filename) : mixed

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

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

Parameters

string $filename

Returns

mixed

_update_stat_cache()

_update_stat_cache(string  $path, mixed  $value) 

Save files / directories to cache

Parameters

string $path
mixed $value

_remove_from_stat_cache()

_remove_from_stat_cache(string  $path) : boolean

Remove files / directories from cache

Parameters

string $path

Returns

boolean

_query_stat_cache()

_query_stat_cache(  $path) : mixed

Checks cache for path

Mainly used by file_exists

Parameters

$path

Returns

mixed

stat()

stat(string  $filename) : mixed

Returns general information about a file.

Returns an array on success and false otherwise.

Parameters

string $filename

Returns

mixed

lstat()

lstat(string  $filename) : mixed

Returns general information about a file or symbolic link.

Returns an array on success and false otherwise.

Parameters

string $filename

Returns

mixed

_stat()

_stat(string  $filename, integer  $type) : mixed

Returns general information about a file or symbolic link

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

Parameters

string $filename
integer $type

Returns

mixed

truncate()

truncate(string  $filename, integer  $new_size) : boolean

Truncates a file to a given length

Parameters

string $filename
integer $new_size

Returns

boolean

touch()

touch(string  $filename, integer  $time = null, integer  $atime = null) : boolean

Sets access and modification time of file.

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

Parameters

string $filename
integer $time
integer $atime

Returns

boolean

chown()

chown(string  $filename, integer  $uid, boolean  $recursive = false) : boolean

Changes file or directory owner

Returns true on success or false on error.

Parameters

string $filename
integer $uid
boolean $recursive

Returns

boolean

chgrp()

chgrp(string  $filename, integer  $gid, boolean  $recursive = false) : boolean

Changes file or directory group

Returns true on success or false on error.

Parameters

string $filename
integer $gid
boolean $recursive

Returns

boolean

chmod()

chmod(integer  $mode, string  $filename, boolean  $recursive = false) : mixed

Set permissions on a file.

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

Parameters

integer $mode
string $filename
boolean $recursive

Returns

mixed

_setstat()

_setstat(string  $filename, string  $attr, boolean  $recursive) : boolean

Sets information about a file

Parameters

string $filename
string $attr
boolean $recursive

Returns

boolean

_setstat_recursive()

_setstat_recursive(string  $path, string  $attr, integer  $i) : boolean

Recursively sets information on directories on the SFTP server

Minimizes directory lookups and SSH_FXP_STATUS requests for speed.

Parameters

string $path
string $attr
integer $i

Returns

boolean

readlink()

readlink(string  $link) : mixed

Return the target of a symbolic link

Parameters

string $link

Returns

mixed

symlink()

symlink(string  $target, string  $link) : boolean

Create a symlink

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

Parameters

string $target
string $link

Returns

boolean

mkdir()

mkdir(string  $dir,   $mode = -1,   $recursive = false) : boolean

Creates a directory.

Parameters

string $dir
$mode
$recursive

Returns

boolean

_mkdir_helper()

_mkdir_helper(string  $dir,   $attr) : boolean

Helper function for directory creation

Parameters

string $dir
$attr

Returns

boolean

rmdir()

rmdir(string  $dir) : boolean

Removes a directory.

Parameters

string $dir

Returns

boolean

_read_put_responses()

_read_put_responses(integer  $i) : boolean

Reads multiple successive SSH_FXP_WRITE responses

Sending an SSH_FXP_WRITE packet and immediately reading its response isn't as efficient as blindly sending out $i SSH_FXP_WRITEs, in succession, and then reading $i responses.

Parameters

integer $i

Returns

boolean

_close_handle()

_close_handle(string  $handle) : boolean

Close handle

Parameters

string $handle

Returns

boolean

get()

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

Downloads a file from the SFTP server.

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

string $remote_file
string $local_file
integer $offset
integer $length
callable|null $progressCallback

Returns

mixed

delete()

delete(string  $path, boolean  $recursive = true) : boolean

Deletes a file on the SFTP server.

Parameters

string $path
boolean $recursive

Returns

boolean

_delete_recursive()

_delete_recursive(string  $path, integer  $i) : boolean

Recursively deletes directories on the SFTP server

Minimizes directory lookups and SSH_FXP_STATUS requests for speed.

Parameters

string $path
integer $i

Returns

boolean

file_exists()

file_exists(string  $path) : boolean

Checks whether a file or directory exists

Parameters

string $path

Returns

boolean

is_dir()

is_dir(string  $path) : boolean

Tells whether the filename is a directory

Parameters

string $path

Returns

boolean

is_file()

is_file(string  $path) : boolean

Tells whether the filename is a regular file

Parameters

string $path

Returns

boolean

is_link()

is_link(string  $path) : boolean

Tells whether the filename is a symbolic link

Parameters

string $path

Returns

boolean

is_readable()

is_readable(string  $path) : boolean

Tells whether a file exists and is readable

Parameters

string $path

Returns

boolean

is_writable()

is_writable(string  $path) : boolean

Tells whether the filename is writable

Parameters

string $path

Returns

boolean

is_writeable()

is_writeable(string  $path) : boolean

Tells whether the filename is writeable

Alias of is_writable

Parameters

string $path

Returns

boolean

fileatime()

fileatime(string  $path) : mixed

Gets last access time of file

Parameters

string $path

Returns

mixed

filemtime()

filemtime(string  $path) : mixed

Gets file modification time

Parameters

string $path

Returns

mixed

fileperms()

fileperms(string  $path) : mixed

Gets file permissions

Parameters

string $path

Returns

mixed

fileowner()

fileowner(string  $path) : mixed

Gets file owner

Parameters

string $path

Returns

mixed

filegroup()

filegroup(string  $path) : mixed

Gets file group

Parameters

string $path

Returns

mixed

filesize()

filesize(string  $path) : mixed

Gets file size

Parameters

string $path

Returns

mixed

filetype()

filetype(string  $path) : mixed

Gets file type

Parameters

string $path

Returns

mixed

_get_stat_cache_prop()

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

Return a stat properity

Uses cache if appropriate.

Parameters

string $path
string $prop

Returns

mixed

_get_lstat_cache_prop()

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

Return an lstat properity

Uses cache if appropriate.

Parameters

string $path
string $prop

Returns

mixed

_get_xstat_cache_prop()

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

Return a stat or lstat properity

Uses cache if appropriate.

Parameters

string $path
string $prop
$type

Returns

mixed

rename()

rename(string  $oldname, string  $newname) : boolean

Renames a file or a directory on the SFTP server

Parameters

string $oldname
string $newname

Returns

boolean

_parseAttributes()

_parseAttributes(string  $response) : array

Parse Attributes

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

Parameters

string $response

Returns

array

_parseMode()

_parseMode(integer  $mode) : integer

Attempt to identify the file type

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

Parameters

integer $mode

Returns

integer

_parseLongname()

_parseLongname(string  $longname) : mixed

Parse Longname

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

string $longname

Returns

mixed

_send_sftp_packet()

_send_sftp_packet(integer  $type, string  $data,   $request_id = 1) : boolean

Sends SFTP Packets

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

Parameters

integer $type
string $data
$request_id

Returns

boolean

_get_sftp_packet()

_get_sftp_packet(  $request_id = null) : string

Receives SFTP Packets

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

Returns

string

getSFTPLog()

getSFTPLog() : string

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

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')

Returns

string —

or Array

getSFTPErrors()

getSFTPErrors() : array

Returns all errors

Returns

array

getLastSFTPError()

getLastSFTPError() : string

Returns the last error

Returns

string

getSupportedVersions()

getSupportedVersions() : array

Get supported SFTP versions

Returns

array