mirror of
https://github.com/phpseclib/phpseclib.git
synced 2024-09-22 12:39:01 +00:00
- the sending of SSH_FXP_WRITE packets are now partially interleaved with the receipt of SSH_FXP_STATUS packets (thanks, TangiX!)
git-svn-id: http://phpseclib.svn.sourceforge.net/svnroot/phpseclib/trunk@88 21d32557-59b3-4da0-833f-c5933fad653e
This commit is contained in:
parent
374c68c312
commit
21184a90e4
@ -48,7 +48,7 @@
|
|||||||
* @author Jim Wigginton <terrafrost@php.net>
|
* @author Jim Wigginton <terrafrost@php.net>
|
||||||
* @copyright MMIX Jim Wigginton
|
* @copyright MMIX Jim Wigginton
|
||||||
* @license http://www.gnu.org/licenses/lgpl.txt
|
* @license http://www.gnu.org/licenses/lgpl.txt
|
||||||
* @version $Id: SFTP.php,v 1.16 2010-02-12 23:02:13 terrafrost Exp $
|
* @version $Id: SFTP.php,v 1.17 2010-02-18 16:56:07 terrafrost Exp $
|
||||||
* @link http://phpseclib.sourceforge.net
|
* @link http://phpseclib.sourceforge.net
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@ -874,7 +874,7 @@ class Net_SFTP extends Net_SSH2 {
|
|||||||
user_error("$data is not a valid file", E_USER_NOTICE);
|
user_error("$data is not a valid file", E_USER_NOTICE);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$fp = fopen($data, 'r');
|
$fp = fopen($data, 'rb');
|
||||||
if (!$fp) {
|
if (!$fp) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -885,8 +885,8 @@ class Net_SFTP extends Net_SSH2 {
|
|||||||
$size = strlen($data);
|
$size = strlen($data);
|
||||||
}
|
}
|
||||||
|
|
||||||
$i = 0;
|
|
||||||
$sftp_packet_size = 34000; // PuTTY uses 4096
|
$sftp_packet_size = 34000; // PuTTY uses 4096
|
||||||
|
$i = 0;
|
||||||
while ($sent < $size) {
|
while ($sent < $size) {
|
||||||
$temp = $mode == NET_SFTP_LOCAL_FILE ? fread($fp, $sftp_packet_size) : $this->_string_shift($data, $sftp_packet_size);
|
$temp = $mode == NET_SFTP_LOCAL_FILE ? fread($fp, $sftp_packet_size) : $this->_string_shift($data, $sftp_packet_size);
|
||||||
$packet = pack('Na*N3a*', strlen($handle), $handle, 0, $sent, strlen($temp), $temp);
|
$packet = pack('Na*N3a*', strlen($handle), $handle, 0, $sent, strlen($temp), $temp);
|
||||||
@ -897,22 +897,18 @@ class Net_SFTP extends Net_SSH2 {
|
|||||||
$sent+= strlen($temp);
|
$sent+= strlen($temp);
|
||||||
|
|
||||||
$i++;
|
$i++;
|
||||||
}
|
|
||||||
|
|
||||||
while ($i--) {
|
if ($i == 50) {
|
||||||
$response = $this->_get_sftp_packet();
|
if (!$this->_read_put_responses($i)) {
|
||||||
if ($this->packet_type != NET_SFTP_STATUS) {
|
$i = 0;
|
||||||
user_error('Expected SSH_FXP_STATUS', E_USER_NOTICE);
|
break;
|
||||||
return false;
|
}
|
||||||
}
|
$i = 0;
|
||||||
|
|
||||||
extract(unpack('Nstatus', $this->_string_shift($response, 4)));
|
|
||||||
if ($status != NET_SFTP_STATUS_OK) {
|
|
||||||
extract(unpack('Nlength', $this->_string_shift($response, 4)));
|
|
||||||
$this->sftp_errors[] = $this->status_codes[$status] . ': ' . $this->_string_shift($response, $length);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->_read_put_responses($i);
|
||||||
|
|
||||||
if ($mode == NET_SFTP_LOCAL_FILE) {
|
if ($mode == NET_SFTP_LOCAL_FILE) {
|
||||||
fclose($fp);
|
fclose($fp);
|
||||||
}
|
}
|
||||||
@ -937,6 +933,36 @@ class Net_SFTP extends Net_SSH2 {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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.
|
||||||
|
*
|
||||||
|
* @param Integer $i
|
||||||
|
* @return Boolean
|
||||||
|
* @access private
|
||||||
|
*/
|
||||||
|
function _read_put_responses($i)
|
||||||
|
{
|
||||||
|
while ($i--) {
|
||||||
|
$response = $this->_get_sftp_packet();
|
||||||
|
if ($this->packet_type != NET_SFTP_STATUS) {
|
||||||
|
user_error('Expected SSH_FXP_STATUS', E_USER_NOTICE);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
extract(unpack('Nstatus', $this->_string_shift($response, 4)));
|
||||||
|
if ($status != NET_SFTP_STATUS_OK) {
|
||||||
|
extract(unpack('Nlength', $this->_string_shift($response, 4)));
|
||||||
|
$this->sftp_errors[] = $this->status_codes[$status] . ': ' . $this->_string_shift($response, $length);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $i < 0;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Downloads a file from the SFTP server.
|
* Downloads a file from the SFTP server.
|
||||||
*
|
*
|
||||||
@ -999,7 +1025,7 @@ class Net_SFTP extends Net_SSH2 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ($local_file !== false) {
|
if ($local_file !== false) {
|
||||||
$fp = fopen($local_file, 'w');
|
$fp = fopen($local_file, 'wb');
|
||||||
if (!$fp) {
|
if (!$fp) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user