Net_SFTP
class Net_SFTP extends Net_SSH2 (View source)
Pure-PHP implementations of SFTP.
Properties
string | $identifier | The SSH identifier | from Net_SSH2 |
object | $fsock | The Socket Object | from Net_SSH2 |
int | $bitmap | Execution Bitmap | from Net_SSH2 |
string | $errors | Error information | from Net_SSH2 |
array|false | $server_identifier | Server Identifier | from Net_SSH2 |
array|false | $kex_algorithms | Key Exchange Algorithms | from Net_SSH2 |
string|false | $kex_algorithm | Key Exchange Algorithm | from Net_SSH2 |
int | $kex_dh_group_size_min | Minimum Diffie-Hellman Group Bit Size in RFC 4419 Key Exchange Methods | from Net_SSH2 |
int | $kex_dh_group_size_preferred | Preferred Diffie-Hellman Group Bit Size in RFC 4419 Key Exchange Methods | from Net_SSH2 |
int | $kex_dh_group_size_max | Maximum Diffie-Hellman Group Bit Size in RFC 4419 Key Exchange Methods | from Net_SSH2 |
array|false | $server_host_key_algorithms | Server Host Key Algorithms | from Net_SSH2 |
array|false | $encryption_algorithms_client_to_server | Encryption Algorithms: Client to Server | from Net_SSH2 |
array|false | $encryption_algorithms_server_to_client | Encryption Algorithms: Server to Client | from Net_SSH2 |
array|false | $mac_algorithms_client_to_server | MAC Algorithms: Client to Server | from Net_SSH2 |
array|false | $mac_algorithms_server_to_client | MAC Algorithms: Server to Client | from Net_SSH2 |
array|false | $compression_algorithms_client_to_server | Compression Algorithms: Client to Server | from Net_SSH2 |
array|false | $compression_algorithms_server_to_client | Compression Algorithms: Server to Client | from Net_SSH2 |
array|false | $languages_server_to_client | Languages: Server to Client | from Net_SSH2 |
array|false | $languages_client_to_server | Languages: Client to Server | from Net_SSH2 |
array | $preferred | Preferred Algorithms | from Net_SSH2 |
int | $encrypt_block_size | Block Size for Server to Client Encryption | from Net_SSH2 |
int | $decrypt_block_size | Block Size for Client to Server Encryption | from Net_SSH2 |
object | $decrypt | Server to Client Encryption Object | from Net_SSH2 |
object | $encrypt | Client to Server Encryption Object | from Net_SSH2 |
object | $hmac_create | Client to Server HMAC Object | from Net_SSH2 |
object | $hmac_check | Server to Client HMAC Object | from Net_SSH2 |
int | $hmac_size | Size of server to client HMAC | from Net_SSH2 |
string | $server_public_host_key | Server Public Host Key | from Net_SSH2 |
string | $session_id | Session identifier | from Net_SSH2 |
string | $exchange_hash | Exchange hash | from Net_SSH2 |
array | $message_numbers | Message Numbers | from Net_SSH2 |
array | $disconnect_reasons | Disconnection Message 'reason codes' defined in RFC4253 | from Net_SSH2 |
array | $channel_open_failure_reasons | SSH_MSG_CHANNEL_OPEN_FAILURE 'reason codes', defined in RFC4254 | from Net_SSH2 |
array | $terminal_modes | Terminal Modes | from Net_SSH2 |
array | $channel_extended_data_type_codes | SSH_MSG_CHANNEL_EXTENDED_DATA's data_type_codes | from Net_SSH2 |
int | $send_seq_no | Send Sequence Number | from Net_SSH2 |
int | $get_seq_no | Get Sequence Number | from Net_SSH2 |
array | $server_channels | Server Channels | from Net_SSH2 |
array | $channel_buffers | Channel Buffers | from Net_SSH2 |
array | $channel_status | Channel Status | from Net_SSH2 |
array | $packet_size_client_to_server | Packet Size | from Net_SSH2 |
array | $message_number_log | Message Number Log | from Net_SSH2 |
array | $message_log | Message Log | from Net_SSH2 |
int | $window_size | The Window Size | from Net_SSH2 |
int | $window_resize | What we resize the window to | from Net_SSH2 |
array | $window_size_server_to_client | Window size, server to client | from Net_SSH2 |
array | $window_size_client_to_server | Window size, client to server | from Net_SSH2 |
string | $signature | Server signature | from Net_SSH2 |
string | $signature_format | Server signature format | from Net_SSH2 |
array | $interactiveBuffer | Interactive Buffer | from Net_SSH2 |
int | $log_size | Current log size | from Net_SSH2 |
$timeout | Timeout | from Net_SSH2 | |
$curTimeout | Current Timeout | from Net_SSH2 | |
$keepAlive | Keep Alive Interval | from Net_SSH2 | |
resource | $realtime_log_file | Real-time log file pointer | from Net_SSH2 |
int | $realtime_log_size | Real-time log file size | from Net_SSH2 |
bool | $signature_validated | Has the signature been validated? | from Net_SSH2 |
$realtime_log_wrap | Real-time log file wrap boolean | from Net_SSH2 | |
$quiet_mode | Flag to suppress stderr from output | from Net_SSH2 | |
int | $last_packet | Time of first network activity | from Net_SSH2 |
int | $exit_status | Exit status returned from ssh if any | from Net_SSH2 |
bool | $request_pty | Flag to request a PTY when using exec() | from Net_SSH2 |
bool | $in_request_pty_exec | Flag set while exec() is running when using enablePTY() | from Net_SSH2 |
bool | $in_subsystem | Flag set after startSubsystem() is called | from Net_SSH2 |
string | $stdErrorLog | Contents of stdError | from Net_SSH2 |
string | $last_interactive_response | The Last Interactive Response | from Net_SSH2 |
array | $keyboard_requests_responses | Keyboard Interactive Request / Responses | from Net_SSH2 |
string | $banner_message | Banner Message | from Net_SSH2 |
bool | $is_timeout | Did read() timeout or return normally? | from Net_SSH2 |
string | $log_boundary | Log Boundary | from Net_SSH2 |
int | $log_long_width | Log Long Width | from Net_SSH2 |
int | $log_short_width | Log Short Width | from Net_SSH2 |
string | $host | Hostname | from Net_SSH2 |
int | $port | Port Number | from Net_SSH2 |
int | $windowColumns | Number of columns for terminal window size | from Net_SSH2 |
int | $windowRows | Number of columns for terminal window size | from Net_SSH2 |
int | $crypto_engine | Crypto Engine | from Net_SSH2 |
System_SSH_Agent | $agent | A System_SSH_Agent for use in the SSH2 Agent Forwarding scenario | from Net_SSH2 |
bool | $send_id_string_first | Send the identification string first? | from Net_SSH2 |
bool | $send_kex_first | Send the key exchange initiation packet first? | from Net_SSH2 |
bool | $bad_key_size_fix | Some versions of OpenSSH incorrectly calculate the key size | from Net_SSH2 |
bool | $retry_connect | Should we try to re-connect to re-establish keys? | from Net_SSH2 |
string|false | $binary_packet_buffer | Binary Packet Buffer | from Net_SSH2 |
string|false | $preferred_signature_format | Preferred Signature Format | from Net_SSH2 |
array | $auth | Authentication Credentials | from Net_SSH2 |
array | $packet_types | Packet Types | |
array | $status_codes | Status Codes | |
bool | $use_request_id | The Request ID | |
int | $packet_type | The Packet Type | |
string | $packet_buffer | Packet Buffer | |
array | $extensions | Extensions supported by the server | |
int | $version | Server SFTP version | |
string | $pwd | Current working directory | |
array | $packet_type_log | Packet Type Log | |
array | $packet_log | Packet Log | |
array | $sftp_errors | Error information | |
array | $stat_cache | Stat Cache | |
array | $max_sftp_packet | Max SFTP Packet Size | |
bool | $use_stat_cache | Stat Cache Flag | |
array | $sortOptions | Sort Options | |
bool | $canonicalize_paths | Canonicalization Flag | |
array | $requestBuffer | Request Buffers | |
bool | $preserveTime | Preserve timestamps on file downloads / uploads | |
bool | $channel_close | Was the last packet due to the channels being closed or not? |
Methods
Default Constructor.
PHP4 compatible Default Constructor.
Maps an encryption algorithm name to the number of key bytes.
Maps an encryption algorithm name to an instance of a subclass of \phpseclib\Crypt\Base.
Tests whether or not proposed algorithm has a potential for issues
Login
Login via keyboard-interactive authentication
Handle the keyboard-interactive requests / responses.
Returns the output of an interactive shell
Pings a server connection, or tries to reconnect if the connection has gone down
Resets a connection for re-use
Gets channel data
Closes and flushes a channel
Disconnect
Returns a log of the packets that have been sent and received.
Formats a log for printing
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.
Return a list of the key exchange algorithms the server supports.
Return a list of the host key (public key) algorithms the server supports.
Return a list of the (symmetric key) encryption algorithms the server supports, when receiving stuff from the client.
Return a list of the (symmetric key) encryption algorithms the server supports, when sending stuff to the client.
Return a list of the MAC algorithms the server supports, when receiving stuff from the client.
Return a list of the MAC algorithms the server supports, when sending stuff to the client.
Return a list of the compression algorithms the server supports, when receiving stuff from the client.
Return a list of the compression algorithms the server supports, when sending stuff to the client.
Return a list of the languages the server supports, when sending stuff to the client.
Return a list of the languages the server supports, when receiving stuff from the client.
Returns a list of KEX algorithms that phpseclib supports
Returns a list of host key algorithms that phpseclib supports
Returns a list of symmetric key algorithms that phpseclib supports
Returns a list of MAC algorithms that phpseclib supports
Returns a list of compression algorithms that phpseclib supports
Accepts an associative array with up to four parameters as described at https://www.php.net/manual/en/function.ssh2-connect.php
Sets the number of columns and rows for the terminal window size.
Return the list of authentication methods that may productively continue authentication.
PHP4 compatible Default Constructor.
(Re)initializes the SFTP channel
Disable the stat cache
Enable the stat cache
Clear the stat cache
Enable path canonicalization
Enable path canonicalization
Returns the current directory name
Logs errors
Returns canonicalized absolute pathname
Canonicalize the Server-Side Path Name
Changes the current directory
Returns a list of files in the given directory
Helper method for nlist
Returns a detailed list of files in the given directory
Reads a list, be it detailed or not, of files in the given directory
Compares two rawlist entries using parameters set by setListOrder()
Defines how nlist() and rawlist() will be sorted - if at all.
Returns the file size, in bytes, or false, on failure
Save files / directories to cache
Remove files / directories from cache
Checks cache for path
Returns general information about a file.
Returns general information about a file or symbolic link.
Returns general information about a file or symbolic link
Truncates a file to a given length
Sets access and modification time of file.
Changes file or directory owner
Changes file or directory group
Set permissions on a file.
Sets information about a file
Recursively sets information on directories on the SFTP server
Return the target of a symbolic link
Create a symlink
Creates a directory.
Helper function for directory creation
Removes a directory.
Uploads a file to the SFTP server.
Reads multiple successive SSH_FXP_WRITE responses
Close handle
Downloads a file from the SFTP server.
Deletes a file on the SFTP server.
Recursively deletes directories on the SFTP server
Checks whether a file or directory exists
Tells whether the filename is a directory
Tells whether the filename is a regular file
Tells whether the filename is a symbolic link
Tells whether a file exists and is readable
Tells whether the filename is writable
Tells whether the filename is writeable
Gets last access time of file
Gets file modification time
Gets file permissions
Gets file owner
Gets file group
Gets file size
Gets file type
Return a stat properity
Return an lstat properity
Return a stat or lstat properity
Renames a file or a directory on the SFTP server
Parse Attributes
Attempt to identify the file type
Parse Longname
Sends SFTP Packets
Receives SFTP Packets
Returns a log of the packets that have been sent and received.
Returns all errors
Returns the last error
Get supported SFTP versions
Enable Date Preservation
Disable Date Preservation
Details
Net_SSH2
__construct(mixed $host, int $port = 22, int $timeout = 10)
Default Constructor.
Connects to an SFTP server
Net_SSH2(mixed $host, int $port = 22, int $timeout = 10)
PHP4 compatible Default Constructor.
setCryptoEngine(int $engine)
Set Crypto Engine Mode
Possible $engine values: CRYPT_MODE_INTERNAL, CRYPT_MODE_MCRYPT
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
bool
_connect()
Connect to an SSHv2 server
string
_generate_identifier()
Generates the SSH identifier
You should overwrite this method in your own class if you want to use another identifier
_key_exchange(string $kexinit_payload_server = false)
Key Exchange
int|null
_encryption_algorithm_to_key_size(string $algorithm)
Maps an encryption algorithm name to the number of key bytes.
mixed
_encryption_algorithm_to_crypt_instance(string $algorithm)
Maps an encryption algorithm name to an instance of a subclass of \phpseclib\Crypt\Base.
bool
_bad_algorithm_candidate(string $algorithm)
Tests whether or not proposed algorithm has a potential for issues
bool
login(string $username)
Login
bool
_login(string $username)
Login Helper
bool
_login_helper(string $username, string $password = null)
Login Helper
bool
_keyboard_interactive_login(string $username, string $password)
Login via keyboard-interactive authentication
See {@link http://tools.ietf.org/html/rfc4256 RFC4256} for details. This is not a full-featured keyboard-interactive authenticator.
bool
_keyboard_interactive_process()
Handle the keyboard-interactive requests / responses.
bool
_ssh_agent_login(string $username, System_SSH_Agent $agent)
Login with an ssh-agent provided key
bool
_privatekey_login(string $username, Crypt_RSA $privatekey)
Login with an RSA private key
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.
setKeepAlive(int $interval)
Set Keep Alive
Sends an SSH2_MSG_IGNORE message every x seconds, if x is a positive non-zero number.
getStdError()
Get the output from stdError
string
exec(string $command, callable $callback = null)
Execute Command
If $callback 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.
bool
_initShell()
Creates an interactive shell
int
_get_interactive_channel()
Return the channel to be used with read() / write()
int
_get_open_channel()
Return an available open channel
string|bool
read(string $expect = '', int $mode = NET_SSH2_READ_SIMPLE)
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 == NET_SSH2_READ_REGEX, a regular expression.
bool
write(string $cmd)
Inputs a command into an interactive shell.
bool
startSubsystem(string $subsystem)
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.
bool
stopSubsystem()
Stops a subsystem.
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()
Is timeout?
Did exec() or read() return because they timed out or because they encountered the end?
disconnect()
Disconnect
__destruct()
Destructor.
Will be called, automatically, if you're supporting just PHP5. If you're supporting PHP4, you'll need to call disconnect().
bool
isConnected()
Is the connection still active?
bool
isAuthenticated()
Have you successfully been logged in?
bool
ping()
Pings a server connection, or tries to reconnect if the connection has gone down
Inspired by http://php.net/manual/en/mysqli.ping.php
bool
_reconnect()
In situ reconnect method
_reset_connection(int $reason)
Resets a connection for re-use
string
_get_binary_packet($skip_channel_filter = false)
Gets Binary Packets
See '6. Binary Packet Protocol' of rfc4253 for more info.
string
_filter($payload, $skip_channel_filter)
Filter Binary Packets
Because some binary packets need to be ignored...
enableQuietMode()
Enable Quiet Mode
Suppress stderr from output
disableQuietMode()
Disable Quiet Mode
Show stderr in output
bool
isQuietModeEnabled()
Returns whether Quiet Mode is enabled or not
enablePTY()
Enable request-pty when using exec()
disablePTY()
Disable request-pty when using exec()
bool
isPTYEnabled()
Returns whether request-pty is enabled or not
mixed|bool
_get_channel_packet(int $client_channel, bool $skip_extended = false)
Gets channel data
Returns the data as a string if it's available and false if not.
bool
_send_binary_packet(string $data, string $logged = null)
Sends Binary Packets
See '6. Binary Packet Protocol' of rfc4253 for more info.
_append_log(string $message_number, string $message)
Logs data packets
Makes sure that only the last 1MB worth of packets will be logged
bool
_send_channel_packet(int $client_channel, string $data)
Sends channel data
Spans multiple SSH_MSG_CHANNEL_DATAs if appropriate
bool
_close_channel(int $client_channel, bool $want_reply = false)
Closes and flushes a channel
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.
bool
_disconnect(int $reason)
Disconnect
string
_string_shift(string $string, int $index = 1)
String Shift
Inspired by array_shift
_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|false|string
getLog()
Returns a log of the packets that have been sent and received.
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')
string
_format_log(array $message_log, array $message_number_log)
Formats a log for printing
string
_format_log_helper(array $matches)
Helper function for _format_log
For use with preg_replace_callback()
_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
mixed
_array_intersect_first(array $array1, array $array2)
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.
string[]
getErrors()
Returns all errors
string
getLastError()
Returns the last error
string
getServerIdentification()
Return the server identification.
array
getKexAlgorithms()
Return a list of the key exchange algorithms the server supports.
array
getServerHostKeyAlgorithms()
Return a list of the host key (public key) algorithms the server supports.
array
getEncryptionAlgorithmsClient2Server()
Return a list of the (symmetric key) encryption algorithms the server supports, when receiving stuff from the client.
array
getEncryptionAlgorithmsServer2Client()
Return a list of the (symmetric key) encryption algorithms the server supports, when sending stuff to the client.
array
getMACAlgorithmsClient2Server()
Return a list of the MAC algorithms the server supports, when receiving stuff from the client.
array
getMACAlgorithmsServer2Client()
Return a list of the MAC algorithms the server supports, when sending stuff to the client.
array
getCompressionAlgorithmsClient2Server()
Return a list of the compression algorithms the server supports, when receiving stuff from the client.
array
getCompressionAlgorithmsServer2Client()
Return a list of the compression algorithms the server supports, when sending stuff to the client.
array
getLanguagesServer2Client()
Return a list of the languages the server supports, when sending stuff to the client.
array
getLanguagesClient2Server()
Return a list of the languages the server supports, when receiving stuff from the client.
array
getServerAlgorithms()
Returns a list of algorithms the server supports
array
getSupportedKEXAlgorithms()
Returns a list of KEX algorithms that phpseclib supports
array
getSupportedHostKeyAlgorithms()
Returns a list of host key algorithms that phpseclib supports
array
getSupportedEncryptionAlgorithms()
Returns a list of symmetric key algorithms that phpseclib supports
array
getSupportedMACAlgorithms()
Returns a list of MAC algorithms that phpseclib supports
array
getSupportedCompressionAlgorithms()
Returns a list of compression algorithms that phpseclib supports
array
getAlgorithmsNegotiated()
Return list of negotiated algorithms
Uses the same format as https://www.php.net/ssh2-methods-negotiated
setPreferredAlgorithms(array $methods)
Accepts an associative array with up to four parameters as described at https://www.php.net/manual/en/function.ssh2-connect.php
string
getBannerMessage()
Returns the banner message.
Quoting from the RFC, "in some jurisdictions, sending a warning message before authentication may be relevant for getting legal protection."
mixed
getServerPublicHostKey()
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.
false|int
getExitStatus()
Returns the exit status of an SSH command or false.
int
getWindowColumns()
Returns the number of columns for the terminal window size.
int
getWindowRows()
Returns the number of rows for the terminal window size.
setWindowColumns(int $value)
Sets the number of columns for the terminal window size.
setWindowRows(int $value)
Sets the number of rows for the terminal window size.
setWindowSize(int $columns = 80, int $rows = 24)
Sets the number of columns and rows for the terminal window size.
_updateLogHistory(string $old, string $new)
Update packet types in log history
array|null
getAuthMethodsToContinue()
Return the list of authentication methods that may productively continue authentication.
Net_SFTP(string $host, int $port = 22, int $timeout = 10)
PHP4 compatible Default Constructor.
bool
_init_sftp_connection()
(Re)initializes the SFTP channel
disableStatCache()
Disable the stat cache
enableStatCache()
Enable the stat cache
clearStatCache()
Clear the stat cache
enablePathCanonicalization()
Enable path canonicalization
disablePathCanonicalization()
Enable path canonicalization
mixed
pwd()
Returns the current directory name
_logError(string $response, int $status = -1)
Logs errors
mixed
realpath(string $path)
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.
mixed
_realpath(string $path)
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.
bool
chdir(string $dir)
Changes the current directory
mixed
nlist(string $dir = '.', bool $recursive = false)
Returns a list of files in the given directory
mixed
_nlist_helper(string $dir, bool $recursive, string $relativeDir)
Helper method for nlist
mixed
rawlist(string $dir = '.', bool $recursive = false)
Returns a detailed list of files in the given directory
mixed
_list(string $dir, bool $raw = true)
Reads a list, be it detailed or not, of files in the given directory
int
_comparator(array $a, array $b)
Compares two rawlist entries using parameters set by setListOrder()
Intended for use with uasort()
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
mixed
size(string $filename)
Returns the file size, in bytes, or false, on failure
Files larger than 4GB will show up as being exactly 4GB.
_update_stat_cache(string $path, mixed $value)
Save files / directories to cache
bool
_remove_from_stat_cache(string $path)
Remove files / directories from cache
mixed
_query_stat_cache(string $path)
Checks cache for path
Mainly used by file_exists
mixed
stat(string $filename)
Returns general information about a file.
Returns an array on success and false otherwise.
mixed
lstat(string $filename)
Returns general information about a file or symbolic link.
Returns an array on success and false otherwise.
mixed
_stat(string $filename, int $type)
Returns general information about a file or symbolic link
Determines information without calling Net_SFTP::realpath(). The second parameter can be either NET_SFTP_STAT or NET_SFTP_LSTAT.
bool
truncate(string $filename, int $new_size)
Truncates a file to a given length
bool
touch(string $filename, int $time = null, int $atime = null)
Sets access and modification time of file.
If the file does not exist, it will be created.
bool
chown(string $filename, int $uid, bool $recursive = false)
Changes file or directory owner
Returns true on success or false on error.
bool
chgrp(string $filename, int $gid, bool $recursive = false)
Changes file or directory group
Returns true on success or false on error.
mixed
chmod(int $mode, string $filename, bool $recursive = false)
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.
bool
_setstat(string $filename, string $attr, bool $recursive)
Sets information about a file
bool
_setstat_recursive(string $path, string $attr, int $i)
Recursively sets information on directories on the SFTP server
Minimizes directory lookups and SSH_FXP_STATUS requests for speed.
mixed
readlink(string $link)
Return the target of a symbolic link
bool
symlink(string $target, string $link)
Create a symlink
symlink() creates a symbolic link to the existing target with the specified name link.
bool
mkdir(string $dir, int $mode = -1, bool $recursive = false)
Creates a directory.
bool
_mkdir_helper(string $dir, int $mode)
Helper function for directory creation
bool
rmdir(string $dir)
Removes a directory.
bool
put(string $remote_file, string|resource $data, int $mode = NET_SFTP_STRING, int $start = -1, int $local_start = -1, callable|null $progressCallback = null)
Uploads a file to the SFTP server.
By default, Net_SFTP::put() does not read from the local filesystem. $data is dumped directly into $remote_file. So, for example, if you set $data to 'filename.ext' and then do Net_SFTP::get(), you will get a file, twelve bytes long, containing 'filename.ext' as its contents.
Setting $mode to NET_SFTP_LOCAL_FILE will change the above behavior. With NET_SFTP_LOCAL_FILE, $remote_file will contain as many bytes as filename.ext does on your local filesystem. If your filename.ext is 1MB then that is how large $remote_file will be, as well.
If $data is a resource then it'll be used as a resource instead.
Setting $mode to NET_SFTP_CALLBACK will use $data as callback function, which gets only one parameter -- number of bytes to return, and returns a string if there is some data or null if there is no more data
Currently, only binary mode is supported. As such, if the line endings need to be adjusted, you will need to take care of that, yourself.
$mode can take an additional two parameters - NET_SFTP_RESUME and NET_SFTP_RESUME_START. These are bitwise AND'd with $mode. So if you want to resume upload of a 300mb file on the local file system you'd set $mode to the following:
NET_SFTP_LOCAL_FILE | NET_SFTP_RESUME
If you wanted to simply append the full contents of a local file to the full contents of a remote file you'd replace NET_SFTP_RESUME with NET_SFTP_RESUME_START.
If $mode & (NET_SFTP_RESUME | NET_SFTP_RESUME_START) then NET_SFTP_RESUME_START will be assumed.
$start and $local_start give you more fine grained control over this process and take precident over NET_SFTP_RESUME when they're non-negative. ie. $start could let you write at the end of a file (like NET_SFTP_RESUME) or in the middle of one. $local_start could let you start your reading from the end of a file (like NET_SFTP_RESUME_START) or in the middle of one.
Setting $local_start to > 0 or $mode | NET_SFTP_RESUME_START doesn't do anything unless $mode | NET_SFTP_LOCAL_FILE.
bool
_read_put_responses(int $i)
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.
bool
_close_handle(string $handle)
Close handle
mixed
get(string $remote_file, string $local_file = false, int $offset = 0, int $length = -1, callable|null $progressCallback = null)
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.
bool
delete(string $path, bool $recursive = true)
Deletes a file on the SFTP server.
bool
_delete_recursive(string $path, int $i)
Recursively deletes directories on the SFTP server
Minimizes directory lookups and SSH_FXP_STATUS requests for speed.
bool
file_exists(string $path)
Checks whether a file or directory exists
bool
is_dir(string $path)
Tells whether the filename is a directory
bool
is_file(string $path)
Tells whether the filename is a regular file
bool
is_link(string $path)
Tells whether the filename is a symbolic link
bool
is_readable(string $path)
Tells whether a file exists and is readable
bool
is_writable(string $path)
Tells whether the filename is writable
bool
is_writeable(string $path)
Tells whether the filename is writeable
Alias of is_writable
mixed
fileatime(string $path)
Gets last access time of file
mixed
filemtime(string $path)
Gets file modification time
mixed
fileperms(string $path)
Gets file permissions
mixed
fileowner(string $path)
Gets file owner
mixed
filegroup(string $path)
Gets file group
mixed
filesize(string $path)
Gets file size
mixed
filetype(string $path)
Gets file type
mixed
_get_stat_cache_prop(string $path, string $prop)
Return a stat properity
Uses cache if appropriate.
mixed
_get_lstat_cache_prop(string $path, string $prop)
Return an lstat properity
Uses cache if appropriate.
mixed
_get_xstat_cache_prop(string $path, string $prop, mixed $type)
Return a stat or lstat properity
Uses cache if appropriate.
bool
rename(string $oldname, string $newname)
Renames a file or a directory on the SFTP server
array
_parseAttributes(string $response)
Parse Attributes
See '7. File Attributes' of draft-ietf-secsh-filexfer-13 for more info.
int
_parseMode(int $mode)
Attempt to identify the file type
Quoting the SFTP RFC, "Implementations MUST NOT send bits that are not defined" but they seem to anyway
mixed
_parseLongname(string $longname)
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 {@link http://tools.ietf.org/html/draft-ietf-secsh-filexfer-04#section-5.2 SFTPv4 type constants}.
If the longname is in an unrecognized format bool(false) is returned.
bool
_send_sftp_packet(int $type, string $data, int $request_id = 1)
Sends SFTP Packets
See '6. General Packet Format' of draft-ietf-secsh-filexfer-13 for more info.
string
_get_sftp_packet($request_id = null)
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.
string
getSFTPLog()
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')
array
getSFTPErrors()
Returns all errors
string
getLastSFTPError()
Returns the last error
array
getSupportedVersions()
Get supported SFTP versions
enableDatePreservation()
Enable Date Preservation
disableDatePreservation()
Disable Date Preservation