Edit File by line
/home/barbar84/www/wp-conte.../plugins/worker/src/PHPSecLi.../Net
File: SFTP.php
<?php
[0] Fix | Delete
[1] Fix | Delete
/**
[2] Fix | Delete
* Pure-PHP implementation of SFTP.
[3] Fix | Delete
*
[4] Fix | Delete
* PHP versions 4 and 5
[5] Fix | Delete
*
[6] Fix | Delete
* Currently only supports SFTPv2 and v3, which, according to wikipedia.org, "is the most widely used version,
[7] Fix | Delete
* implemented by the popular OpenSSH SFTP server". If you want SFTPv4/5/6 support, provide me with access
[8] Fix | Delete
* to an SFTPv4/5/6 server.
[9] Fix | Delete
*
[10] Fix | Delete
* The API for this library is modeled after the API from PHP's {@link http://php.net/book.ftp FTP extension}.
[11] Fix | Delete
*
[12] Fix | Delete
* Here's a short example of how to use this library:
[13] Fix | Delete
* <code>
[14] Fix | Delete
* <?php
[15] Fix | Delete
* include 'Net/SFTP.php';
[16] Fix | Delete
*
[17] Fix | Delete
* $sftp = new Net_SFTP('www.domain.tld');
[18] Fix | Delete
* if (!$sftp->login('username', 'password')) {
[19] Fix | Delete
* exit('Login Failed');
[20] Fix | Delete
* }
[21] Fix | Delete
*
[22] Fix | Delete
* echo $sftp->pwd() . "\r\n";
[23] Fix | Delete
* $sftp->put('filename.ext', 'hello, world!');
[24] Fix | Delete
* print_r($sftp->nlist());
[25] Fix | Delete
* ?>
[26] Fix | Delete
* </code>
[27] Fix | Delete
*
[28] Fix | Delete
* LICENSE: Permission is hereby granted, free of charge, to any person obtaining a copy
[29] Fix | Delete
* of this software and associated documentation files (the "Software"), to deal
[30] Fix | Delete
* in the Software without restriction, including without limitation the rights
[31] Fix | Delete
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
[32] Fix | Delete
* copies of the Software, and to permit persons to whom the Software is
[33] Fix | Delete
* furnished to do so, subject to the following conditions:
[34] Fix | Delete
*
[35] Fix | Delete
* The above copyright notice and this permission notice shall be included in
[36] Fix | Delete
* all copies or substantial portions of the Software.
[37] Fix | Delete
*
[38] Fix | Delete
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
[39] Fix | Delete
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
[40] Fix | Delete
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
[41] Fix | Delete
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
[42] Fix | Delete
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
[43] Fix | Delete
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
[44] Fix | Delete
* THE SOFTWARE.
[45] Fix | Delete
*
[46] Fix | Delete
* @category Net
[47] Fix | Delete
* @package Net_SFTP
[48] Fix | Delete
* @author Jim Wigginton <terrafrost@php.net>
[49] Fix | Delete
* @copyright MMIX Jim Wigginton
[50] Fix | Delete
* @license http://www.opensource.org/licenses/mit-license.html MIT License
[51] Fix | Delete
* @link http://phpseclib.sourceforge.net
[52] Fix | Delete
*/
[53] Fix | Delete
[54] Fix | Delete
/**
[55] Fix | Delete
* Include Net_SSH2
[56] Fix | Delete
*/
[57] Fix | Delete
if (!class_exists('Net_SSH2')) {
[58] Fix | Delete
require_once dirname(__FILE__).'/SSH2.php';
[59] Fix | Delete
}
[60] Fix | Delete
[61] Fix | Delete
/**#@+
[62] Fix | Delete
* @access public
[63] Fix | Delete
* @see Net_SFTP::getLog()
[64] Fix | Delete
*/
[65] Fix | Delete
/**
[66] Fix | Delete
* Returns the message numbers
[67] Fix | Delete
*/
[68] Fix | Delete
define('NET_SFTP_LOG_SIMPLE', NET_SSH2_LOG_SIMPLE);
[69] Fix | Delete
/**
[70] Fix | Delete
* Returns the message content
[71] Fix | Delete
*/
[72] Fix | Delete
define('NET_SFTP_LOG_COMPLEX', NET_SSH2_LOG_COMPLEX);
[73] Fix | Delete
/**
[74] Fix | Delete
* Outputs the message content in real-time.
[75] Fix | Delete
*/
[76] Fix | Delete
define('NET_SFTP_LOG_REALTIME', 3);
[77] Fix | Delete
/**#@-*/
[78] Fix | Delete
[79] Fix | Delete
/**
[80] Fix | Delete
* SFTP channel constant
[81] Fix | Delete
*
[82] Fix | Delete
* Net_SSH2::exec() uses 0 and Net_SSH2::read() / Net_SSH2::write() use 1.
[83] Fix | Delete
*
[84] Fix | Delete
* @see Net_SSH2::_send_channel_packet()
[85] Fix | Delete
* @see Net_SSH2::_get_channel_packet()
[86] Fix | Delete
* @access private
[87] Fix | Delete
*/
[88] Fix | Delete
define('NET_SFTP_CHANNEL', 0x100);
[89] Fix | Delete
[90] Fix | Delete
/**#@+
[91] Fix | Delete
* @access public
[92] Fix | Delete
* @see Net_SFTP::put()
[93] Fix | Delete
*/
[94] Fix | Delete
/**
[95] Fix | Delete
* Reads data from a local file.
[96] Fix | Delete
*/
[97] Fix | Delete
define('NET_SFTP_LOCAL_FILE', 1);
[98] Fix | Delete
/**
[99] Fix | Delete
* Reads data from a string.
[100] Fix | Delete
*/
[101] Fix | Delete
// this value isn't really used anymore but i'm keeping it reserved for historical reasons
[102] Fix | Delete
define('NET_SFTP_STRING', 2);
[103] Fix | Delete
/**
[104] Fix | Delete
* Resumes an upload
[105] Fix | Delete
*/
[106] Fix | Delete
define('NET_SFTP_RESUME', 4);
[107] Fix | Delete
/**
[108] Fix | Delete
* Append a local file to an already existing remote file
[109] Fix | Delete
*/
[110] Fix | Delete
define('NET_SFTP_RESUME_START', 8);
[111] Fix | Delete
/**#@-*/
[112] Fix | Delete
[113] Fix | Delete
/**
[114] Fix | Delete
* Pure-PHP implementations of SFTP.
[115] Fix | Delete
*
[116] Fix | Delete
* @package Net_SFTP
[117] Fix | Delete
* @author Jim Wigginton <terrafrost@php.net>
[118] Fix | Delete
* @access public
[119] Fix | Delete
*/
[120] Fix | Delete
class Net_SFTP extends Net_SSH2
[121] Fix | Delete
{
[122] Fix | Delete
/**
[123] Fix | Delete
* Packet Types
[124] Fix | Delete
*
[125] Fix | Delete
* @see Net_SFTP::Net_SFTP()
[126] Fix | Delete
* @var Array
[127] Fix | Delete
* @access private
[128] Fix | Delete
*/
[129] Fix | Delete
public $packet_types = array();
[130] Fix | Delete
[131] Fix | Delete
/**
[132] Fix | Delete
* Status Codes
[133] Fix | Delete
*
[134] Fix | Delete
* @see Net_SFTP::Net_SFTP()
[135] Fix | Delete
* @var Array
[136] Fix | Delete
* @access private
[137] Fix | Delete
*/
[138] Fix | Delete
public $status_codes = array();
[139] Fix | Delete
[140] Fix | Delete
/**
[141] Fix | Delete
* The Request ID
[142] Fix | Delete
*
[143] Fix | Delete
* The request ID exists in the off chance that a packet is sent out-of-order. Of course, this library doesn't support
[144] Fix | Delete
* concurrent actions, so it's somewhat academic, here.
[145] Fix | Delete
*
[146] Fix | Delete
* @var Integer
[147] Fix | Delete
* @see Net_SFTP::_send_sftp_packet()
[148] Fix | Delete
* @access private
[149] Fix | Delete
*/
[150] Fix | Delete
public $request_id = false;
[151] Fix | Delete
[152] Fix | Delete
/**
[153] Fix | Delete
* The Packet Type
[154] Fix | Delete
*
[155] Fix | Delete
* The request ID exists in the off chance that a packet is sent out-of-order. Of course, this library doesn't support
[156] Fix | Delete
* concurrent actions, so it's somewhat academic, here.
[157] Fix | Delete
*
[158] Fix | Delete
* @var Integer
[159] Fix | Delete
* @see Net_SFTP::_get_sftp_packet()
[160] Fix | Delete
* @access private
[161] Fix | Delete
*/
[162] Fix | Delete
public $packet_type = -1;
[163] Fix | Delete
[164] Fix | Delete
/**
[165] Fix | Delete
* Packet Buffer
[166] Fix | Delete
*
[167] Fix | Delete
* @var String
[168] Fix | Delete
* @see Net_SFTP::_get_sftp_packet()
[169] Fix | Delete
* @access private
[170] Fix | Delete
*/
[171] Fix | Delete
public $packet_buffer = '';
[172] Fix | Delete
[173] Fix | Delete
/**
[174] Fix | Delete
* Extensions supported by the server
[175] Fix | Delete
*
[176] Fix | Delete
* @var Array
[177] Fix | Delete
* @see Net_SFTP::_initChannel()
[178] Fix | Delete
* @access private
[179] Fix | Delete
*/
[180] Fix | Delete
public $extensions = array();
[181] Fix | Delete
[182] Fix | Delete
/**
[183] Fix | Delete
* Server SFTP version
[184] Fix | Delete
*
[185] Fix | Delete
* @var Integer
[186] Fix | Delete
* @see Net_SFTP::_initChannel()
[187] Fix | Delete
* @access private
[188] Fix | Delete
*/
[189] Fix | Delete
public $version;
[190] Fix | Delete
[191] Fix | Delete
/**
[192] Fix | Delete
* Current working directory
[193] Fix | Delete
*
[194] Fix | Delete
* @var String
[195] Fix | Delete
* @see Net_SFTP::_realpath()
[196] Fix | Delete
* @see Net_SFTP::chdir()
[197] Fix | Delete
* @access private
[198] Fix | Delete
*/
[199] Fix | Delete
public $pwd = false;
[200] Fix | Delete
[201] Fix | Delete
/**
[202] Fix | Delete
* Packet Type Log
[203] Fix | Delete
*
[204] Fix | Delete
* @see Net_SFTP::getLog()
[205] Fix | Delete
* @var Array
[206] Fix | Delete
* @access private
[207] Fix | Delete
*/
[208] Fix | Delete
public $packet_type_log = array();
[209] Fix | Delete
[210] Fix | Delete
/**
[211] Fix | Delete
* Packet Log
[212] Fix | Delete
*
[213] Fix | Delete
* @see Net_SFTP::getLog()
[214] Fix | Delete
* @var Array
[215] Fix | Delete
* @access private
[216] Fix | Delete
*/
[217] Fix | Delete
public $packet_log = array();
[218] Fix | Delete
[219] Fix | Delete
/**
[220] Fix | Delete
* Error information
[221] Fix | Delete
*
[222] Fix | Delete
* @see Net_SFTP::getSFTPErrors()
[223] Fix | Delete
* @see Net_SFTP::getLastSFTPError()
[224] Fix | Delete
* @var String
[225] Fix | Delete
* @access private
[226] Fix | Delete
*/
[227] Fix | Delete
public $sftp_errors = array();
[228] Fix | Delete
[229] Fix | Delete
/**
[230] Fix | Delete
* Stat Cache
[231] Fix | Delete
*
[232] Fix | Delete
* Rather than always having to open a directory and close it immediately there after to see if a file is a directory
[233] Fix | Delete
* we'll cache the results.
[234] Fix | Delete
*
[235] Fix | Delete
* @see Net_SFTP::_update_stat_cache()
[236] Fix | Delete
* @see Net_SFTP::_remove_from_stat_cache()
[237] Fix | Delete
* @see Net_SFTP::_query_stat_cache()
[238] Fix | Delete
* @var Array
[239] Fix | Delete
* @access private
[240] Fix | Delete
*/
[241] Fix | Delete
public $stat_cache = array();
[242] Fix | Delete
[243] Fix | Delete
/**
[244] Fix | Delete
* Max SFTP Packet Size
[245] Fix | Delete
*
[246] Fix | Delete
* @see Net_SFTP::Net_SFTP()
[247] Fix | Delete
* @see Net_SFTP::get()
[248] Fix | Delete
* @var Array
[249] Fix | Delete
* @access private
[250] Fix | Delete
*/
[251] Fix | Delete
public $max_sftp_packet;
[252] Fix | Delete
[253] Fix | Delete
/**
[254] Fix | Delete
* Stat Cache Flag
[255] Fix | Delete
*
[256] Fix | Delete
* @see Net_SFTP::disableStatCache()
[257] Fix | Delete
* @see Net_SFTP::enableStatCache()
[258] Fix | Delete
* @var Boolean
[259] Fix | Delete
* @access private
[260] Fix | Delete
*/
[261] Fix | Delete
public $use_stat_cache = true;
[262] Fix | Delete
[263] Fix | Delete
/**
[264] Fix | Delete
* Sort Options
[265] Fix | Delete
*
[266] Fix | Delete
* @see Net_SFTP::_comparator()
[267] Fix | Delete
* @see Net_SFTP::setListOrder()
[268] Fix | Delete
* @var Array
[269] Fix | Delete
* @access private
[270] Fix | Delete
*/
[271] Fix | Delete
public $sortOptions = array();
[272] Fix | Delete
[273] Fix | Delete
/**
[274] Fix | Delete
* Default Constructor.
[275] Fix | Delete
*
[276] Fix | Delete
* Connects to an SFTP server
[277] Fix | Delete
*
[278] Fix | Delete
* @param String $host
[279] Fix | Delete
* @param optional Integer $port
[280] Fix | Delete
* @param optional Integer $timeout
[281] Fix | Delete
*
[282] Fix | Delete
* @return Net_SFTP
[283] Fix | Delete
* @access public
[284] Fix | Delete
*/
[285] Fix | Delete
public function __construct($host, $port = 22, $timeout = 10)
[286] Fix | Delete
{
[287] Fix | Delete
parent::__construct($host, $port, $timeout);
[288] Fix | Delete
[289] Fix | Delete
$this->max_sftp_packet = 1 << 15;
[290] Fix | Delete
[291] Fix | Delete
$this->packet_types = array(
[292] Fix | Delete
1 => 'NET_SFTP_INIT',
[293] Fix | Delete
2 => 'NET_SFTP_VERSION',
[294] Fix | Delete
/* the format of SSH_FXP_OPEN changed between SFTPv4 and SFTPv5+:
[295] Fix | Delete
SFTPv5+: http://tools.ietf.org/html/draft-ietf-secsh-filexfer-13#section-8.1.1
[296] Fix | Delete
pre-SFTPv5 : http://tools.ietf.org/html/draft-ietf-secsh-filexfer-04#section-6.3 */
[297] Fix | Delete
3 => 'NET_SFTP_OPEN',
[298] Fix | Delete
4 => 'NET_SFTP_CLOSE',
[299] Fix | Delete
5 => 'NET_SFTP_READ',
[300] Fix | Delete
6 => 'NET_SFTP_WRITE',
[301] Fix | Delete
7 => 'NET_SFTP_LSTAT',
[302] Fix | Delete
9 => 'NET_SFTP_SETSTAT',
[303] Fix | Delete
11 => 'NET_SFTP_OPENDIR',
[304] Fix | Delete
12 => 'NET_SFTP_READDIR',
[305] Fix | Delete
13 => 'NET_SFTP_REMOVE',
[306] Fix | Delete
14 => 'NET_SFTP_MKDIR',
[307] Fix | Delete
15 => 'NET_SFTP_RMDIR',
[308] Fix | Delete
16 => 'NET_SFTP_REALPATH',
[309] Fix | Delete
17 => 'NET_SFTP_STAT',
[310] Fix | Delete
/* the format of SSH_FXP_RENAME changed between SFTPv4 and SFTPv5+:
[311] Fix | Delete
SFTPv5+: http://tools.ietf.org/html/draft-ietf-secsh-filexfer-13#section-8.3
[312] Fix | Delete
pre-SFTPv5 : http://tools.ietf.org/html/draft-ietf-secsh-filexfer-04#section-6.5 */
[313] Fix | Delete
18 => 'NET_SFTP_RENAME',
[314] Fix | Delete
19 => 'NET_SFTP_READLINK',
[315] Fix | Delete
20 => 'NET_SFTP_SYMLINK',
[316] Fix | Delete
[317] Fix | Delete
101 => 'NET_SFTP_STATUS',
[318] Fix | Delete
102 => 'NET_SFTP_HANDLE',
[319] Fix | Delete
/* the format of SSH_FXP_NAME changed between SFTPv3 and SFTPv4+:
[320] Fix | Delete
SFTPv4+: http://tools.ietf.org/html/draft-ietf-secsh-filexfer-13#section-9.4
[321] Fix | Delete
pre-SFTPv4 : http://tools.ietf.org/html/draft-ietf-secsh-filexfer-02#section-7 */
[322] Fix | Delete
103 => 'NET_SFTP_DATA',
[323] Fix | Delete
104 => 'NET_SFTP_NAME',
[324] Fix | Delete
105 => 'NET_SFTP_ATTRS',
[325] Fix | Delete
[326] Fix | Delete
200 => 'NET_SFTP_EXTENDED',
[327] Fix | Delete
);
[328] Fix | Delete
$this->status_codes = array(
[329] Fix | Delete
0 => 'NET_SFTP_STATUS_OK',
[330] Fix | Delete
1 => 'NET_SFTP_STATUS_EOF',
[331] Fix | Delete
2 => 'NET_SFTP_STATUS_NO_SUCH_FILE',
[332] Fix | Delete
3 => 'NET_SFTP_STATUS_PERMISSION_DENIED',
[333] Fix | Delete
4 => 'NET_SFTP_STATUS_FAILURE',
[334] Fix | Delete
5 => 'NET_SFTP_STATUS_BAD_MESSAGE',
[335] Fix | Delete
6 => 'NET_SFTP_STATUS_NO_CONNECTION',
[336] Fix | Delete
7 => 'NET_SFTP_STATUS_CONNECTION_LOST',
[337] Fix | Delete
8 => 'NET_SFTP_STATUS_OP_UNSUPPORTED',
[338] Fix | Delete
9 => 'NET_SFTP_STATUS_INVALID_HANDLE',
[339] Fix | Delete
10 => 'NET_SFTP_STATUS_NO_SUCH_PATH',
[340] Fix | Delete
11 => 'NET_SFTP_STATUS_FILE_ALREADY_EXISTS',
[341] Fix | Delete
12 => 'NET_SFTP_STATUS_WRITE_PROTECT',
[342] Fix | Delete
13 => 'NET_SFTP_STATUS_NO_MEDIA',
[343] Fix | Delete
14 => 'NET_SFTP_STATUS_NO_SPACE_ON_FILESYSTEM',
[344] Fix | Delete
15 => 'NET_SFTP_STATUS_QUOTA_EXCEEDED',
[345] Fix | Delete
16 => 'NET_SFTP_STATUS_UNKNOWN_PRINCIPAL',
[346] Fix | Delete
17 => 'NET_SFTP_STATUS_LOCK_CONFLICT',
[347] Fix | Delete
18 => 'NET_SFTP_STATUS_DIR_NOT_EMPTY',
[348] Fix | Delete
19 => 'NET_SFTP_STATUS_NOT_A_DIRECTORY',
[349] Fix | Delete
20 => 'NET_SFTP_STATUS_INVALID_FILENAME',
[350] Fix | Delete
21 => 'NET_SFTP_STATUS_LINK_LOOP',
[351] Fix | Delete
22 => 'NET_SFTP_STATUS_CANNOT_DELETE',
[352] Fix | Delete
23 => 'NET_SFTP_STATUS_INVALID_PARAMETER',
[353] Fix | Delete
24 => 'NET_SFTP_STATUS_FILE_IS_A_DIRECTORY',
[354] Fix | Delete
25 => 'NET_SFTP_STATUS_BYTE_RANGE_LOCK_CONFLICT',
[355] Fix | Delete
26 => 'NET_SFTP_STATUS_BYTE_RANGE_LOCK_REFUSED',
[356] Fix | Delete
27 => 'NET_SFTP_STATUS_DELETE_PENDING',
[357] Fix | Delete
28 => 'NET_SFTP_STATUS_FILE_CORRUPT',
[358] Fix | Delete
29 => 'NET_SFTP_STATUS_OWNER_INVALID',
[359] Fix | Delete
30 => 'NET_SFTP_STATUS_GROUP_INVALID',
[360] Fix | Delete
31 => 'NET_SFTP_STATUS_NO_MATCHING_BYTE_RANGE_LOCK',
[361] Fix | Delete
);
[362] Fix | Delete
// http://tools.ietf.org/html/draft-ietf-secsh-filexfer-13#section-7.1
[363] Fix | Delete
// the order, in this case, matters quite a lot - see Net_SFTP::_parseAttributes() to understand why
[364] Fix | Delete
$this->attributes = array(
[365] Fix | Delete
0x00000001 => 'NET_SFTP_ATTR_SIZE',
[366] Fix | Delete
0x00000002 => 'NET_SFTP_ATTR_UIDGID', // defined in SFTPv3, removed in SFTPv4+
[367] Fix | Delete
0x00000004 => 'NET_SFTP_ATTR_PERMISSIONS',
[368] Fix | Delete
0x00000008 => 'NET_SFTP_ATTR_ACCESSTIME',
[369] Fix | Delete
// 0x80000000 will yield a floating point on 32-bit systems and converting floating points to integers
[370] Fix | Delete
// yields inconsistent behavior depending on how php is compiled. so we left shift -1 (which, in
[371] Fix | Delete
// two's compliment, consists of all 1 bits) by 31. on 64-bit systems this'll yield 0xFFFFFFFF80000000.
[372] Fix | Delete
// that's not a problem, however, and 'anded' and a 32-bit number, as all the leading 1 bits are ignored.
[373] Fix | Delete
-1 << 31 => 'NET_SFTP_ATTR_EXTENDED',
[374] Fix | Delete
);
[375] Fix | Delete
// http://tools.ietf.org/html/draft-ietf-secsh-filexfer-04#section-6.3
[376] Fix | Delete
// the flag definitions change somewhat in SFTPv5+. if SFTPv5+ support is added to this library, maybe name
[377] Fix | Delete
// the array for that $this->open5_flags and similarily alter the constant names.
[378] Fix | Delete
$this->open_flags = array(
[379] Fix | Delete
0x00000001 => 'NET_SFTP_OPEN_READ',
[380] Fix | Delete
0x00000002 => 'NET_SFTP_OPEN_WRITE',
[381] Fix | Delete
0x00000004 => 'NET_SFTP_OPEN_APPEND',
[382] Fix | Delete
0x00000008 => 'NET_SFTP_OPEN_CREATE',
[383] Fix | Delete
0x00000010 => 'NET_SFTP_OPEN_TRUNCATE',
[384] Fix | Delete
0x00000020 => 'NET_SFTP_OPEN_EXCL',
[385] Fix | Delete
);
[386] Fix | Delete
// http://tools.ietf.org/html/draft-ietf-secsh-filexfer-04#section-5.2
[387] Fix | Delete
// see Net_SFTP::_parseLongname() for an explanation
[388] Fix | Delete
$this->file_types = array(
[389] Fix | Delete
1 => 'NET_SFTP_TYPE_REGULAR',
[390] Fix | Delete
2 => 'NET_SFTP_TYPE_DIRECTORY',
[391] Fix | Delete
3 => 'NET_SFTP_TYPE_SYMLINK',
[392] Fix | Delete
4 => 'NET_SFTP_TYPE_SPECIAL',
[393] Fix | Delete
5 => 'NET_SFTP_TYPE_UNKNOWN',
[394] Fix | Delete
// the followin types were first defined for use in SFTPv5+
[395] Fix | Delete
// http://tools.ietf.org/html/draft-ietf-secsh-filexfer-05#section-5.2
[396] Fix | Delete
6 => 'NET_SFTP_TYPE_SOCKET',
[397] Fix | Delete
7 => 'NET_SFTP_TYPE_CHAR_DEVICE',
[398] Fix | Delete
8 => 'NET_SFTP_TYPE_BLOCK_DEVICE',
[399] Fix | Delete
9 => 'NET_SFTP_TYPE_FIFO',
[400] Fix | Delete
);
[401] Fix | Delete
$this->_define_array(
[402] Fix | Delete
$this->packet_types,
[403] Fix | Delete
$this->status_codes,
[404] Fix | Delete
$this->attributes,
[405] Fix | Delete
$this->open_flags,
[406] Fix | Delete
$this->file_types
[407] Fix | Delete
);
[408] Fix | Delete
[409] Fix | Delete
if (!defined('NET_SFTP_QUEUE_SIZE')) {
[410] Fix | Delete
define('NET_SFTP_QUEUE_SIZE', 50);
[411] Fix | Delete
}
[412] Fix | Delete
}
[413] Fix | Delete
[414] Fix | Delete
/**
[415] Fix | Delete
* Login
[416] Fix | Delete
*
[417] Fix | Delete
* @param String $username
[418] Fix | Delete
* @param optional String $password
[419] Fix | Delete
*
[420] Fix | Delete
* @return Boolean
[421] Fix | Delete
* @access public
[422] Fix | Delete
*/
[423] Fix | Delete
public function login($username)
[424] Fix | Delete
{
[425] Fix | Delete
$args = func_get_args();
[426] Fix | Delete
if (!call_user_func_array(array(&$this, '_login'), $args)) {
[427] Fix | Delete
return false;
[428] Fix | Delete
}
[429] Fix | Delete
[430] Fix | Delete
$this->window_size_server_to_client[NET_SFTP_CHANNEL] = $this->window_size;
[431] Fix | Delete
[432] Fix | Delete
$packet = pack('CNa*N3',
[433] Fix | Delete
NET_SSH2_MSG_CHANNEL_OPEN, strlen('session'), 'session', NET_SFTP_CHANNEL, $this->window_size, 0x4000);
[434] Fix | Delete
[435] Fix | Delete
if (!$this->_send_binary_packet($packet)) {
[436] Fix | Delete
return false;
[437] Fix | Delete
}
[438] Fix | Delete
[439] Fix | Delete
$this->channel_status[NET_SFTP_CHANNEL] = NET_SSH2_MSG_CHANNEL_OPEN;
[440] Fix | Delete
[441] Fix | Delete
$response = $this->_get_channel_packet(NET_SFTP_CHANNEL);
[442] Fix | Delete
if ($response === false) {
[443] Fix | Delete
return false;
[444] Fix | Delete
}
[445] Fix | Delete
[446] Fix | Delete
$packet = pack('CNNa*CNa*',
[447] Fix | Delete
NET_SSH2_MSG_CHANNEL_REQUEST, $this->server_channels[NET_SFTP_CHANNEL], strlen('subsystem'), 'subsystem', 1, strlen('sftp'), 'sftp');
[448] Fix | Delete
if (!$this->_send_binary_packet($packet)) {
[449] Fix | Delete
return false;
[450] Fix | Delete
}
[451] Fix | Delete
[452] Fix | Delete
$this->channel_status[NET_SFTP_CHANNEL] = NET_SSH2_MSG_CHANNEL_REQUEST;
[453] Fix | Delete
[454] Fix | Delete
$response = $this->_get_channel_packet(NET_SFTP_CHANNEL);
[455] Fix | Delete
if ($response === false) {
[456] Fix | Delete
// from PuTTY's psftp.exe
[457] Fix | Delete
$command = "test -x /usr/lib/sftp-server && exec /usr/lib/sftp-server\n".
[458] Fix | Delete
"test -x /usr/local/lib/sftp-server && exec /usr/local/lib/sftp-server\n".
[459] Fix | Delete
"exec sftp-server";
[460] Fix | Delete
// we don't do $this->exec($command, false) because exec() operates on a different channel and plus the SSH_MSG_CHANNEL_OPEN that exec() does
[461] Fix | Delete
// is redundant
[462] Fix | Delete
$packet = pack('CNNa*CNa*',
[463] Fix | Delete
NET_SSH2_MSG_CHANNEL_REQUEST, $this->server_channels[NET_SFTP_CHANNEL], strlen('exec'), 'exec', 1, strlen($command), $command);
[464] Fix | Delete
if (!$this->_send_binary_packet($packet)) {
[465] Fix | Delete
return false;
[466] Fix | Delete
}
[467] Fix | Delete
[468] Fix | Delete
$this->channel_status[NET_SFTP_CHANNEL] = NET_SSH2_MSG_CHANNEL_REQUEST;
[469] Fix | Delete
[470] Fix | Delete
$response = $this->_get_channel_packet(NET_SFTP_CHANNEL);
[471] Fix | Delete
if ($response === false) {
[472] Fix | Delete
return false;
[473] Fix | Delete
}
[474] Fix | Delete
}
[475] Fix | Delete
[476] Fix | Delete
$this->channel_status[NET_SFTP_CHANNEL] = NET_SSH2_MSG_CHANNEL_DATA;
[477] Fix | Delete
[478] Fix | Delete
if (!$this->_send_sftp_packet(NET_SFTP_INIT, "\0\0\0\3")) {
[479] Fix | Delete
return false;
[480] Fix | Delete
}
[481] Fix | Delete
[482] Fix | Delete
$response = $this->_get_sftp_packet();
[483] Fix | Delete
if ($this->packet_type != NET_SFTP_VERSION) {
[484] Fix | Delete
user_error('Expected SSH_FXP_VERSION');
[485] Fix | Delete
[486] Fix | Delete
return false;
[487] Fix | Delete
}
[488] Fix | Delete
[489] Fix | Delete
extract(unpack('Nversion', $this->_string_shift($response, 4)));
[490] Fix | Delete
$this->version = $version;
[491] Fix | Delete
while (!empty($response)) {
[492] Fix | Delete
extract(unpack('Nlength', $this->_string_shift($response, 4)));
[493] Fix | Delete
$key = $this->_string_shift($response, $length);
[494] Fix | Delete
extract(unpack('Nlength', $this->_string_shift($response, 4)));
[495] Fix | Delete
$value = $this->_string_shift($response, $length);
[496] Fix | Delete
$this->extensions[$key] = $value;
[497] Fix | Delete
}
[498] Fix | Delete
[499] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function