MASK_CONSTRUCTOR
MASK_CONSTRUCTOR
Pure-PHP implementations of SFTP.
$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
$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.
$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
__construct(string $host, integer $port = 22, integer $timeout = 10) : \phpseclib\Net\SFTP
Default Constructor.
Connects to an SFTP server
string | $host | |
integer | $port | |
integer | $timeout |
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()
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()
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()
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
_encryption_algorithm_to_key_size(string $algorithm) : integer|null
Maps an encryption algorithm name to the number of key bytes.
string | $algorithm | Name of the encryption algorithm |
Number of bytes as an integer or null for unknown
_encryption_algorithm_to_crypt_instance(string $algorithm) : mixed
Maps an encryption algorithm name to an instance of a subclass of \phpseclib\Crypt\Base.
string | $algorithm | Name of the encryption algorithm |
Instance of \phpseclib\Crypt\Base or null for unknown
_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.
string | $username | |
string | $password |
_ssh_agent_login(string $username, \phpseclib\System\SSH\Agent $agent) : boolean
Login with an ssh-agent provided key
string | $username | |
\phpseclib\System\SSH\Agent | $agent |
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.
string | $command | |
Callback | $callback |
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.
string | $expect | |
integer | $mode |
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.
string | $subsystem |
ping() : boolean
Pings a server connection, or tries to reconnect if the connection has gone down
Inspired by http://php.net/manual/en/mysqli.ping.php
_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.
integer | $client_channel | |
boolean | $want_reply |
_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.
_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.
array | $array1 | |
array | $array2 |
False if intersection is empty, else intersected value.
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.
_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.
string | $path |
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
_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.
string | $filename | |
integer | $type |
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.
integer | $mode | |
string | $filename | |
boolean | $recursive |
_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.
integer | $i |
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.
string | $remote_file | |
string | $local_file | |
integer | $offset | |
integer | $length | |
callable|null | $progressCallback |
_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.
string | $longname |
_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.
$request_id |