Class Net_SFTP
Pure-PHP implementations of SFTP.
-
Net_SSH2
-
Net_SFTP
Methods summary
public
Net_SFTP
|
#
Net_SFTP( String $host, optional $port = 22, optional $timeout = 10 )
Default Constructor.
Connects to an SFTP server
Parameters
- $host
String $host
- $port
optional Integer $port
- $timeout
optional Integer $timeout
Returns
|
public
Boolean
|
#
login( String $username, optional $password = '' )
Login
Parameters
- $username
String $username
- $password
optional String $password
Returns
Boolean
Overrides
|
public
Mixed
|
#
pwd( )
Returns the current directory name
Returns the current directory name
Returns
Mixed
|
public
Mixed
|
#
_realpath( String $dir, optional $check_dir = true )
Canonicalize the Server-Side Path Name
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
$mode is set to NET_SFTP_CONFIRM_DIR (as opposed to NET_SFTP_CONFIRM_NONE, which
is what it is set to by default), false is returned if $dir is not a valid
directory.
Parameters
- $dir
String $dir
- $check_dir
optional Integer $mode
Returns
Mixed
See
|
public
Boolean
|
#
chdir( String $dir )
Changes the current directory
Changes the current directory
Parameters
Returns
Boolean
|
public
Mixed
|
#
nlist( optional $dir = '.' )
Returns a list of files in the given directory
Returns a list of files in the given directory
Parameters
Returns
Mixed
|
public
Mixed
|
#
rawlist( optional $dir = '.' )
Returns a detailed list of files in the given directory
Returns a detailed list of files in the given directory
Parameters
Returns
Mixed
|
public
Mixed
|
#
_list( optional $dir, mixed $raw = true, mixed $realpath = true )
Reads a list, be it detailed or not, of files in the given directory
Reads a list, be it detailed or not, of files in the given directory
Parameters
- $dir
optional String $dir
- $raw
- $realpath
Returns
Mixed
|
public
Mixed
|
#
size( String $filename )
Returns the file size, in bytes, or false, on failure
Returns the file size, in bytes, or false, on failure
Files larger than 4GB will show up as being exactly 4GB.
Parameters
- $filename
String $filename
Returns
Mixed
|
public
|
#
_save_dir( String $dir )
Save directories to cache
Save directories to cache
Parameters
|
public
|
#
_remove_dir( String $dir )
Remove directories from cache
Remove directories from cache
Parameters
|
public
|
#
_is_dir( String $dir )
Checks cache for directory
Checks cache for directory
Parameters
|
public
Mixed
|
#
stat( String $filename )
Returns general information about a file.
Returns general information about a file.
Returns an array on success and false otherwise.
Parameters
- $filename
String $filename
Returns
Mixed
|
public
Mixed
|
#
lstat( String $filename )
Returns general information about a file or symbolic link.
Returns general information about a file or symbolic link.
Returns an array on success and false otherwise.
Parameters
- $filename
String $filename
Returns
Mixed
|
public
Mixed
|
#
_stat( String $filename, Integer $type )
Returns general information about a file or symbolic link
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.
Parameters
- $filename
String $filename
- $type
Integer $type
Returns
Mixed
|
public
Integer
|
#
_identify_type( String $path, Array $stat1, Array $stat2 )
Attempt to identify the file type
Attempt to identify the file type
Parameters
- $path
String $path
- $stat1
Array $stat
- $stat2
Array $lstat
Returns
Integer
|
public
Mixed
|
#
_size( String $filename )
Returns the file size, in bytes, or false, on failure
Returns the file size, in bytes, or false, on failure
Determines the size without calling Net_SFTP::_realpath()
Parameters
- $filename
String $filename
Returns
Mixed
|
public
Mixed
|
#
chmod( Integer $mode, String $filename, mixed $recursive = false )
Set permissions on a file.
Set permissions on a file.
Returns the new file permissions on success or FALSE on error.
Parameters
- $mode
Integer $mode
- $filename
String $filename
- $recursive
Returns
Mixed
|
public
Boolean
|
#
_chmod_recursive( Integer $mode, String $path, mixed & $i )
Recursively chmods directories on the SFTP server
Recursively chmods directories on the SFTP server
Minimizes directory lookups and SSH_FXP_STATUS requests for speed.
Parameters
- $mode
Integer $mode
- $path
String $filename
- $i
Returns
Boolean
|
public
Boolean
|
#
mkdir( String $dir )
Creates a directory.
Parameters
Returns
Boolean
|
public
Boolean
|
#
rmdir( String $dir )
Removes a directory.
Parameters
Returns
Boolean
|
public
Boolean
|
#
put( String $remote_file, String $data, optional $mode = NET_SFTP_STRING )
Uploads a file to the SFTP server.
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.
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.
Parameters
- $remote_file
String $remote_file
- $data
String $data
- $mode
optional Integer $mode
Returns
Boolean
|
public
Boolean
|
#
_read_put_responses( Integer $i )
Reads multiple successive SSH_FXP_WRITE responses
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
Returns
Boolean
|
public
Mixed
|
#
get( String $remote_file, optional $local_file = false )
Downloads a file from the SFTP server.
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
Parameters
- $remote_file
String $remote_file
- $local_file
optional String $local_file
Returns
Mixed
|
public
Boolean
|
#
delete( String $path, Boolean $recursive = true )
Deletes a file on the SFTP server.
Deletes a file on the SFTP server.
Parameters
- $path
String $path
- $recursive
Boolean $recursive
Returns
Boolean
|
public
Boolean
|
#
_delete_recursive( String $path, Integer & $i )
Recursively deletes directories on the SFTP server
Recursively deletes directories on the SFTP server
Minimizes directory lookups and SSH_FXP_STATUS requests for speed.
Parameters
- $path
String $path
- $i
Integer $i
Returns
Boolean
|
public
Boolean
|
#
rename( String $oldname, String $newname )
Renames a file or a directory on the SFTP server
Renames a file or a directory on the SFTP server
Parameters
- $oldname
String $oldname
- $newname
String $newname
Returns
Boolean
|
public
Array
|
#
_parseAttributes( String & $response )
Parse Attributes
See '7. File Attributes' of draft-ietf-secsh-filexfer-13 for more info.
Parameters
- $response
String $response
Returns
Array
|
public
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 SFTPv4 type constants.
If the longname is in an unrecognized format bool(false) is returned.
Parameters
- $longname
String $longname
Returns
Mixed
|
public
Boolean
|
#
_send_sftp_packet( Integer $type, String $data )
Sends SFTP Packets
See '6. General Packet Format' of draft-ietf-secsh-filexfer-13 for more
info.
Parameters
- $type
Integer $type
- $data
String $data
Returns
Boolean
See
|
public
String
|
#
_get_sftp_packet( )
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.
Returns
String
See
|
public
String
|
#
getSFTPLog( )
Returns a log of the packets that have been sent and received.
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
|
public
String
|
#
getSFTPErrors( )
Returns all errors
Returns
String
|
public
String
|
#
getLastSFTPError( )
Returns the last error
Returns
String
|
public
Array
|
#
getSupportedVersions( )
Get supported SFTP versions
Get supported SFTP versions
Returns
Array
|
public
Boolean
|
#
_disconnect( Integer $reason )
Disconnect
Parameters
Returns
Boolean
Overrides
|
Methods inherited from Net_SSH2
Net_SSH2()
,
__destruct()
,
_append_log()
,
_close_channel()
,
_define_array()
,
_filter()
,
_format_log()
,
_get_binary_packet()
,
_get_channel_packet()
,
_initShell()
,
_key_exchange()
,
_keyboard_interactive_login()
,
_keyboard_interactive_process()
,
_privatekey_login()
,
_send_binary_packet()
,
_send_channel_packet()
,
_string_shift()
,
disconnect()
,
exec()
,
getCompressionAlgorithmsClient2Server()
,
getCompressionAlgorithmsServer2Client()
,
getEncryptionAlgorithmsClient2Server()
,
getEncryptionAlgorithmsServer2Client()
,
getErrors()
,
getKexAlgorithms()
,
getLanguagesClient2Server()
,
getLanguagesServer2Client()
,
getLastError()
,
getLog()
,
getMACAlgorithmsClient2Server()
,
getMACAlgorithmsServer2Client()
,
getServerHostKeyAlgorithms()
,
getServerIdentification()
,
getServerPublicHostKey()
,
read()
,
setTimeout()
,
write()
Magic methods summary
Properties summary
public
Array
|
$packet_types |
|
public
Array
|
$status_codes |
|
public
Integer
|
$request_id |
#
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.
See
|
public
Integer
|
$packet_type |
#
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.
See
|
public
String
|
$packet_buffer |
|
public
Array
|
$extensions |
#
Extensions supported by the server
Extensions supported by the server
See
Net_SFTP::_initChannel()
|
public
Integer
|
$version |
#
Server SFTP version
See
Net_SFTP::_initChannel()
|
public
String
|
$pwd |
#
Current working directory
Current working directory
See
|
public
Array
|
$packet_type_log |
|
public
Array
|
$packet_log |
|
public
String
|
$sftp_errors |
|
public
Integer
|
$fileType |
|
public
Array
|
$dirs |
#
Directory Cache
Rather than always having to open a directory and close it immediately there
after to see if a file is a directory or rather than always
See
|
Properties inherited from Net_SSH2
$bitmap
,
$channel_buffers
,
$channel_extended_data_type_codes
,
$channel_open_failure_reasons
,
$channel_status
,
$compression_algorithms_client_to_server
,
$compression_algorithms_server_to_client
,
$curTimeout
,
$decrypt
,
$decrypt_block_size
,
$disconnect_reasons
,
$encrypt
,
$encrypt_block_size
,
$encryption_algorithms_client_to_server
,
$encryption_algorithms_server_to_client
,
$errors
,
$exchange_hash
,
$fsock
,
$get_seq_no
,
$hmac_check
,
$hmac_create
,
$hmac_size
,
$identifier
,
$interactiveBuffer
,
$kex_algorithms
,
$languages_client_to_server
,
$languages_server_to_client
,
$log_size
,
$mac_algorithms_client_to_server
,
$mac_algorithms_server_to_client
,
$message_log
,
$message_number_log
,
$message_numbers
,
$packet_size_client_to_server
,
$realtime_log_file
,
$realtime_log_size
,
$realtime_log_wrap
,
$send_seq_no
,
$server_channels
,
$server_host_key_algorithms
,
$server_identifier
,
$server_public_host_key
,
$session_id
,
$signature
,
$signature_format
,
$signature_validated
,
$terminal_modes
,
$timeout
,
$window_size
,
$window_size_client_to_server