Pure-PHP implementation of SSHv2.
Methods
Default Constructor.
Net_SSH2(String $host, \optional $port, \optional $timeout) : \Net_SSH2
Connects to an SSHv2 server
Parameters
$host
String
$port
\optional
Integer $port
$timeout
\optional
Integer $timeout
Returns
Destructor.
__destruct()
Will be called, automatically, if you're supporting just PHP5. If you're supporting PHP4, you'll need to call
disconnect().
Closes and flushes a channel
_close_channel(Integer $client_channel) : Boolean
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
Integer
Returns
Boolean
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.
Disconnect
_disconnect(Integer $reason) : Boolean
Parameters
$reason
Integer
Returns
Boolean
Filter Binary Packets
_filter($payload) : String
Because some binary packets need to be ignored...
see |
\global\Net_SSH2::_get_binary_packet() |
access |
private |
Parameters
$payload
Returns
String
Gets Binary Packets
_get_binary_packet() : String
See '6. Binary Packet Protocol' of rfc4253 for more info.
see |
\global\Net_SSH2::_send_binary_packet() |
access |
private |
Returns
String
Gets channel data
_get_channel_packet($client_channel, $skip_extended) : Mixed
Returns the data as a string if it's available and false if not.
Parameters
$client_channel
$skip_extended
Returns
Mixed
Creates an interactive shell
_initShell() : Boolean
see |
\global\Net_SSH2::read() |
see |
\global\Net_SSH2::write() |
access |
private |
Returns
Boolean
Key Exchange
_key_exchange(String $kexinit_payload_server)
Parameters
$kexinit_payload_server
String
Login via keyboard-interactive authentication
_keyboard_interactive_login(String $username, String $password) : Boolean
See RFC4256 for details. This is not a full-featured keyboard-interactive authenticator.
Parameters
$username
String
$password
String
Returns
Boolean
Handle the keyboard-interactive requests / responses.
_keyboard_interactive_process() : Boolean
Sends Binary Packets
_send_binary_packet(String $data) : Boolean
See '6. Binary Packet Protocol' of rfc4253 for more info.
see |
\global\Net_SSH2::_get_binary_packet() |
access |
private |
Parameters
$data
String
Returns
Boolean
Sends channel data
_send_channel_packet(Integer $client_channel, String $data) : Boolean
Spans multiple SSH_MSG_CHANNEL_DATAs if appropriate
Parameters
$client_channel
Integer
$data
String
Returns
Boolean
String Shift
_string_shift(String $string, \optional $index) : String
Inspired by array_shift
Parameters
$string
String
$index
\optional
Integer $index
Returns
String
Execute Command
exec(String $command, \optional $block) : String
If $block is set to false then Net_SSH2::_get_channel_packet(NET_SSH2_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
$block
\optional
Boolean $block
Returns
String
Return a list of the compression algorithms the server supports, when receiving stuff from the client.
getCompressionAlgorithmsClient2Server() : Array
Return a list of the compression algorithms the server supports, when sending stuff to the client.
getCompressionAlgorithmsServer2Client() : Array
Return a list of the (symmetric key) encryption algorithms the server supports, when receiving stuff from the client.
getEncryptionAlgorithmsClient2Server() : Array
Return a list of the (symmetric key) encryption algorithms the server supports, when sending stuff to the client.
getEncryptionAlgorithmsServer2Client() : Array
Returns all errors
getErrors() : String
Return a list of the key exchange algorithms the server supports.
getKexAlgorithms() : Array
Return a list of the languages the server supports, when receiving stuff from the client.
getLanguagesClient2Server() : Array
Return a list of the languages the server supports, when sending stuff to the client.
getLanguagesServer2Client() : Array
Returns the last error
getLastError() : String
Returns a log of the packets that have been sent and received.
getLog() : String
Returns a string if NET_SSH2_LOGGING == NET_SSH2_LOG_COMPLEX, an array if NET_SSH2_LOGGING == NET_SSH2_LOG_SIMPLE and false if !defined('NET_SSH2_LOGGING')
Returns
String
or Array
Return a list of the MAC algorithms the server supports, when receiving stuff from the client.
getMACAlgorithmsClient2Server() : Array
Return a list of the MAC algorithms the server supports, when sending stuff to the client.
getMACAlgorithmsServer2Client() : Array
Return a list of the host key (public key) algorithms the server supports.
getServerHostKeyAlgorithms() : Array
Return the server identification.
getServerIdentification() : String
Returns the server public host key.
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.
Returns
Mixed
Returns the output of an interactive shell
read(String $expect, Integer $mode) : String
Returns when there's a match for $expect, which can take the form of a string literal or,
if $mode == NET_SSH2_READ_REGEX, a regular expression.
see |
\global\Net_SSH2::read() |
access |
public |
Parameters
$expect
String
$mode
Integer
Returns
String
Inputs a command into an interactive shell.
write(String $cmd) : Boolean
see |
\global\Net_SSH1::interactiveWrite() |
access |
public |
Parameters
$cmd
String
Returns
Boolean
Properties
Execution Bitmap
$bitmap : Integer
The bits that are set reprsent 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.
Channel Buffers
$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
see |
\global\Net_SSH2::_get_channel_packet() |
see |
\global\Net_SSH2::exec() |
access |
private |
SSH_MSG_CHANNEL_EXTENDED_DATA's data_type_codes
$channel_extended_data_type_codes : Array
SSH_MSG_CHANNEL_OPEN_FAILURE 'reason codes', defined in RFC4254
$channel_open_failure_reasons : Array
see |
\global\Net_SSH2::Net_SSH2() |
access |
private |
Channel Status
$channel_status : Array
Contains the type of the last sent message
see |
\global\Net_SSH2::_get_channel_packet() |
access |
private |
Compression Algorithms: Client to Server
$compression_algorithms_client_to_server : Array
see |
\global\Net_SSH2::getCompressionAlgorithmsClient2Server() |
access |
private |
Compression Algorithms: Server to Client
$compression_algorithms_server_to_client : Array
see |
\global\Net_SSH2::getCompressionAlgorithmsServer2Client() |
access |
private |
Server to Client Encryption Object
$decrypt : Object
see |
\global\Net_SSH2::_get_binary_packet() |
access |
private |
Block Size for Client to Server Encryption
$decrypt_block_size : Integer
see |
\global\Net_SSH2::Net_SSH2() |
see |
\global\Net_SSH2::_get_binary_packet() |
access |
private |
Disconnection Message 'reason codes' defined in RFC4253
$disconnect_reasons : Array
see |
\global\Net_SSH2::Net_SSH2() |
access |
private |
Client to Server Encryption Object
$encrypt : Object
see |
\global\Net_SSH2::_send_binary_packet() |
access |
private |
Block Size for Server to Client Encryption
$encrypt_block_size : Integer
"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
see |
\global\Net_SSH2::Net_SSH2() |
see |
\global\Net_SSH2::_send_binary_packet() |
access |
private |
Encryption Algorithms: Client to Server
$encryption_algorithms_client_to_server : Array
see |
\global\Net_SSH2::getEncryptionAlgorithmsClient2Server() |
access |
private |
Encryption Algorithms: Server to Client
$encryption_algorithms_server_to_client : Array
see |
\global\Net_SSH2::getEncryptionAlgorithmsServer2Client() |
access |
private |
Error information
$errors : String
see |
\global\Net_SSH2::getErrors() |
see |
\global\Net_SSH2::getLastError() |
access |
private |
Exchange hash
$exchange_hash : String
The current exchange hash
see |
\global\Net_SSH2::_key_exchange() |
access |
private |
The Socket Object
$fsock : Object
Get Sequence Number
$get_seq_no : Integer
See 'Section 6.4. Data Integrity' of rfc4253 for more info.
see |
\global\Net_SSH2::_get_binary_packet() |
access |
private |
Server to Client HMAC Object
$hmac_check : Object
see |
\global\Net_SSH2::_get_binary_packet() |
access |
private |
Client to Server HMAC Object
$hmac_create : Object
see |
\global\Net_SSH2::_send_binary_packet() |
access |
private |
Size of server to client HMAC
$hmac_size : Integer
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.
see |
\global\Net_SSH2::_get_binary_packet() |
access |
private |
The SSH identifier
$identifier : String
Interactive Buffer
$interactiveBuffer : Array
see |
\global\Net_SSH2::read() |
access |
private |
Key Exchange Algorithms
$kex_algorithms : Array
see |
\global\Net_SSH2::getKexAlgorithims() |
access |
private |
Languages: Client to Server
$languages_client_to_server : Array
see |
\global\Net_SSH2::getLanguagesClient2Server() |
access |
private |
Languages: Server to Client
$languages_server_to_client : Array
see |
\global\Net_SSH2::getLanguagesServer2Client() |
access |
private |
MAC Algorithms: Client to Server
$mac_algorithms_client_to_server : Array
see |
\global\Net_SSH2::getMACAlgorithmsClient2Server() |
access |
private |
MAC Algorithms: Server to Client
$mac_algorithms_server_to_client : Array
see |
\global\Net_SSH2::getMACAlgorithmsServer2Client() |
access |
private |
Message Log
$message_log : Array
see |
\global\Net_SSH2::getLog() |
access |
private |
Message Number Log
$message_number_log : Array
see |
\global\Net_SSH2::getLog() |
access |
private |
Message Numbers
$message_numbers : Array
see |
\global\Net_SSH2::Net_SSH2() |
access |
private |
Packet Size
$packet_size_client_to_server : Array
Maximum packet size indexed by channel
see |
\global\Net_SSH2::_send_channel_packet() |
access |
private |
Send Sequence Number
$send_seq_no : Integer
See 'Section 6.4. Data Integrity' of rfc4253 for more info.
see |
\global\Net_SSH2::_send_binary_packet() |
access |
private |
Server Channels
$server_channels : Array
Maps client channels to server channels
see |
\global\Net_SSH2::_get_channel_packet() |
see |
\global\Net_SSH2::exec() |
access |
private |
Server Host Key Algorithms
$server_host_key_algorithms : Array
see |
\global\Net_SSH2::getServerHostKeyAlgorithms() |
access |
private |
Server Identifier
$server_identifier : String
see |
\global\Net_SSH2::getServerIdentification() |
access |
private |
Server Public Host Key
$server_public_host_key : String
see |
\global\Net_SSH2::getServerPublicHostKey() |
access |
private |
Session identifer
$session_id : String
"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
see |
\global\Net_SSH2::_key_exchange() |
access |
private |
Server signature
$signature : String
Verified against $this->session_id
see |
\global\Net_SSH2::getServerPublicHostKey() |
access |
private |
Terminal Modes
$terminal_modes : Array
The Window Size
$window_size : Integer
Bytes the other party can send before it must wait for the window to be adjusted (0x7FFFFFFF = 4GB)
see |
\global\Net_SSH2::_send_channel_packet() |
see |
\global\Net_SSH2::exec() |
access |
private |
Window size
$window_size_client_to_server : Array
Window size indexed by channel
see |
\global\Net_SSH2::_send_channel_packet() |
access |
private |