- Net_SFTP now has better support for uploading large files than it did before, per this:

http://www.frostjedi.com/phpbb/viewtopic.php?f=46&t=10415


git-svn-id: http://phpseclib.svn.sourceforge.net/svnroot/phpseclib/trunk@40 21d32557-59b3-4da0-833f-c5933fad653e
This commit is contained in:
Jim Wigginton 2009-06-09 04:00:38 +00:00
parent 039cd313ee
commit d6339e014f
5 changed files with 44 additions and 89 deletions

View File

@ -2,7 +2,7 @@
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
/**
* Pure-PHP implementations of RC4.
* Pure-PHP implementation of RC4.
*
* Uses mcrypt, if available, and an internal implementation, otherwise.
*
@ -55,7 +55,7 @@
* @author Jim Wigginton <terrafrost@php.net>
* @copyright MMVII Jim Wigginton
* @license http://www.gnu.org/licenses/lgpl.txt
* @version $Id: RC4.php,v 1.7 2009-05-27 21:36:53 terrafrost Exp $
* @version $Id: RC4.php,v 1.8 2009-06-09 04:00:38 terrafrost Exp $
* @link http://phpseclib.sourceforge.net
*/

View File

@ -2,7 +2,7 @@
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
/**
* Pure-PHP implementations of Triple DES.
* Pure-PHP implementation of Triple DES.
*
* Uses mcrypt, if available, and an internal implementation, otherwise. Operates in the EDE3 mode (encrypt-decrypt-encrypt).
*
@ -47,7 +47,7 @@
* @author Jim Wigginton <terrafrost@php.net>
* @copyright MMVII Jim Wigginton
* @license http://www.gnu.org/licenses/lgpl.txt
* @version $Id: TripleDES.php,v 1.7 2009-05-27 16:15:23 terrafrost Exp $
* @version $Id: TripleDES.php,v 1.8 2009-06-09 04:00:38 terrafrost Exp $
* @link http://phpseclib.sourceforge.net
*/

View File

@ -2,7 +2,7 @@
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
/**
* Pure-PHP implementations of SFTP.
* Pure-PHP implementation of SFTP.
*
* PHP versions 4 and 5
*
@ -48,7 +48,7 @@
* @author Jim Wigginton <terrafrost@php.net>
* @copyright MMIX Jim Wigginton
* @license http://www.gnu.org/licenses/lgpl.txt
* @version $Id: SFTP.php,v 1.3 2009-05-30 16:48:42 terrafrost Exp $
* @version $Id: SFTP.php,v 1.4 2009-06-09 04:00:38 terrafrost Exp $
* @link http://phpseclib.sourceforge.net
*/
@ -875,67 +875,43 @@ class Net_SFTP extends Net_SSH2 {
}
$sent = 0;
$size = filesize($data);
while ($sent < $size) {
/*
"The 'maximum packet size' specifies the maximum size of an individual data packet that can be sent to the
sender. For example, one might want to use smaller packets for interactive connections to get better
interactive response on slow links."
-- http://tools.ietf.org/html/rfc4254#section-5.1
per that, we're going to assume that the 'maximum packet size' field of the SSH_MSG_CHANNEL_OPEN message
does not apply to the client. the client is the one who sends the SSH_MSG_CHANNEL_OPEN message, anyway,
so it's not as if the above could be referring to the server.
the reason that's mentioned is because sending $this->packet_size as the payload will result in a packet
that's larger than $this->packet_size, but that's not a problem, as per the above.
*/
if ($initialize) {
$temp = fread($fp, $this->packet_size);
$sent+= strlen($temp);
$packet = pack('NCN2a*N3a*',
$size + strlen($handle) + 21, NET_SFTP_WRITE, $this->request_id, strlen($handle), $handle, 0, 0, $size, $temp
);
$initialize = false;
if (defined('NET_SFTP_LOGGING')) {
$log_index = count($this->packet_type_log);
$this->packet_type_log[] = '<- ' . $this->packet_types[$packet_type];
$this->packet_log[] = $packet;
}
} else {
$packet = fread($fp, $this->packet_size);
$sent+= strlen($packet);
if (defined('NET_SFTP_LOGGING')) {
$this->packet_log[$log_index].= $packet;
}
}
if (!$this->_send_channel_packet($packet)) {
fclose($fp);
return false;
}
}
fclose($fp);
} else {
while (strlen($data)) {
if ($initialize) {
$packet = pack('NCN2a*N3a*',
strlen($data) + strlen($handle) + 21, NET_SFTP_WRITE, $this->request_id, strlen($handle), $handle, 0, 0, strlen($data),
$this->_string_shift($data, $this->packet_size)
);
$initialize = false;
} else {
$packet = $this->_string_shift($data, $this->packet_size);
}
if (!$this->_send_channel_packet($packet)) {
return false;
}
$sent = 0;
$size = strlen($data);
}
while ($sent < $size) {
/*
"The 'maximum packet size' specifies the maximum size of an individual data packet that can be sent to the
sender. For example, one might want to use smaller packets for interactive connections to get better
interactive response on slow links."
-- http://tools.ietf.org/html/rfc4254#section-5.1
per that, we're going to assume that the 'maximum packet size' field of the SSH_MSG_CHANNEL_OPEN message
does not apply to the client. the client is the one who sends the SSH_MSG_CHANNEL_OPEN message, anyway,
so it's not as if the above could be referring to the server.
the reason that's mentioned is because sending $this->packet_size as the payload will result in a packet
that's larger than $this->packet_size, but that's not a problem, as per the above.
*/
$temp = $mode == NET_SFTP_LOCAL_FILE ? fread($fp, $this->packet_size) : $this->_string_shift($data, $this->packet_size);
$packet = pack('Na*N3a*', strlen($handle), $handle, 0, $sent, strlen($temp), $temp);
if (!$this->_send_sftp_packet(NET_SFTP_WRITE, $packet)) {
fclose($fp);
return false;
}
$sent+= strlen($temp);
$this->_get_sftp_packet();
if ($this->packet_type != NET_SFTP_STATUS) {
user_error('Expected SSH_FXP_STATUS', E_USER_NOTICE);
return false;
}
}
$this->_get_sftp_packet();
if ($this->packet_type != NET_SFTP_STATUS) {
user_error('Expected SSH_FXP_STATUS', E_USER_NOTICE);
return false;
if ($mode == NET_SFTP_LOCAL_FILE) {
fclose($fp);
}
if (!$this->_send_sftp_packet(NET_SFTP_CLOSE, pack('Na*', strlen($handle), $handle))) {
@ -1213,25 +1189,6 @@ class Net_SFTP extends Net_SSH2 {
$this->packet_log[] = $data;
}
return $this->_send_channel_packet($data);
}
/**
* Sends Channel Packets
*
* If this function were in Net_SSH2, there'd have to be an additional server channel parameter since the Net_SSH2 object
* doesn't currently have one. Plus, it wouldn't actually make a lot of sense for Net_SSH2 even to have one - if it did
* and if Net_SSH2::exec() used it then Net_SFTP::exec() would also use it (through inheritance) and you'd have the
* single server channel being overwritten and... all in all, I think this is easier.
*
* @param Integer $type
* @param String $data
* @see Net_SFTP::_send_sftp_packet()
* @return Boolean
* @access private
*/
function _send_channel_packet($data)
{
return $this->_send_binary_packet(pack('CN2a*', NET_SSH2_MSG_CHANNEL_DATA, $this->server_channel, strlen($data), $data));
}

View File

@ -2,7 +2,7 @@
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
/**
* Pure-PHP implementations of SSHv1.
* Pure-PHP implementation of SSHv1.
*
* PHP versions 4 and 5
*
@ -65,7 +65,7 @@
* @author Jim Wigginton <terrafrost@php.net>
* @copyright MMVII Jim Wigginton
* @license http://www.gnu.org/licenses/lgpl.txt
* @version $Id: SSH1.php,v 1.11 2009-05-30 15:46:32 terrafrost Exp $
* @version $Id: SSH1.php,v 1.12 2009-06-09 04:00:38 terrafrost Exp $
* @link http://phpseclib.sourceforge.net
*/

View File

@ -2,7 +2,7 @@
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
/**
* Pure-PHP implementations of SSHv2.
* Pure-PHP implementation of SSHv2.
*
* PHP versions 4 and 5
*
@ -41,7 +41,7 @@
* @author Jim Wigginton <terrafrost@php.net>
* @copyright MMVII Jim Wigginton
* @license http://www.gnu.org/licenses/lgpl.txt
* @version $Id: SSH2.php,v 1.17 2009-05-30 16:40:31 terrafrost Exp $
* @version $Id: SSH2.php,v 1.18 2009-06-09 04:00:38 terrafrost Exp $
* @link http://phpseclib.sourceforge.net
*/
@ -931,9 +931,7 @@ class Net_SSH2 {
$s = $s->modPow($e, $n);
$s = $s->toBytes();
$h = chr(0x00) . chr(0x30) . chr(0x21) . chr(0x30) . chr(0x09) . chr(0x06) . chr(0x05) . chr(0x2B) .
chr(0x0E) . chr(0x03) . chr(0x02) . chr(0x1A) . chr(0x05) . chr(0x00) . chr(0x04) . chr(0x14) .
pack('H*', sha1($source));
$h = pack('N4H*', 0x00302130, 0x0906052B, 0x0E03021A, 0x05000414, sha1($source));
$h = chr(0x01) . str_repeat(chr(0xFF), $nLength - 3 - strlen($h)) . $h;
if ($s != $h) {