From c01b8fc4ed7d191140b812f4cc1215cd7bee5979 Mon Sep 17 00:00:00 2001 From: terrafrost Date: Sun, 15 Dec 2013 00:43:20 -0600 Subject: [PATCH] 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 --- phpseclib/Net/SCP.php | 2 +- phpseclib/Net/SSH2.php | 11 +++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/phpseclib/Net/SCP.php b/phpseclib/Net/SCP.php index 88180cac..fe7be342 100644 --- a/phpseclib/Net/SCP.php +++ b/phpseclib/Net/SCP.php @@ -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); diff --git a/phpseclib/Net/SSH2.php b/phpseclib/Net/SSH2.php index dad03697..803262dc 100644 --- a/phpseclib/Net/SSH2.php +++ b/phpseclib/Net/SSH2.php @@ -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; }