SCP: Tweaks

sending the close channel packet right after the eof seems to make some scp transfers terminate prematurely.

unfortunately, sometimes this behavior is undesirable as it is in this case:

http://www.frostjedi.com/phpbb3/viewtopic.php?f=46&t=29457

hence the $want_reply parameter

also, this commit makes the scp packet length account for the length portion
This commit is contained in:
terrafrost 2013-12-15 00:43:20 -06:00
parent fcfc0e2c00
commit c01b8fc4ed
2 changed files with 10 additions and 3 deletions

View File

@ -181,7 +181,7 @@ class Net_SCP {
}
if ($this->mode == NET_SCP_SSH2) {
$this->packet_size = $this->ssh->packet_size_client_to_server[NET_SSH2_CHANNEL_EXEC];
$this->packet_size = $this->ssh->packet_size_client_to_server[NET_SSH2_CHANNEL_EXEC] - 4;
}
$remote_file = basename($remote_file);

View File

@ -3103,16 +3103,19 @@ class Net_SSH2 {
* for SCP more than anything.
*
* @param Integer $client_channel
* @param Boolean $want_reply
* @return Boolean
* @access private
*/
function _close_channel($client_channel)
function _close_channel($client_channel, $want_reply = false)
{
// see http://tools.ietf.org/html/rfc4254#section-5.3
$this->_send_binary_packet(pack('CN', NET_SSH2_MSG_CHANNEL_EOF, $this->server_channels[$client_channel]));
$this->_send_binary_packet(pack('CN', NET_SSH2_MSG_CHANNEL_CLOSE, $this->server_channels[$client_channel]));
if (!$want_reply) {
$this->_send_binary_packet(pack('CN', NET_SSH2_MSG_CHANNEL_CLOSE, $this->server_channels[$client_channel]));
}
$this->channel_status[$client_channel] = NET_SSH2_MSG_CHANNEL_CLOSE;
@ -3120,6 +3123,10 @@ class Net_SSH2 {
while (!is_bool($this->_get_channel_packet($client_channel)));
if ($want_reply) {
$this->_send_binary_packet(pack('CN', NET_SSH2_MSG_CHANNEL_CLOSE, $this->server_channels[$client_channel]));
}
if ($this->bitmap & NET_SSH2_MASK_SHELL) {
$this->bitmap&= ~NET_SSH2_MASK_SHELL;
}