mirror of
https://github.com/danog/tgseclib.git
synced 2024-11-27 04:34:45 +01:00
SFTP: Add support for files larger than 2GB
0x7FFFFFFF is about 2GB. To support larger files floating point is used
This commit is contained in:
parent
aa3e6c1a99
commit
2c80ac8aca
@ -1025,7 +1025,7 @@ class Net_SFTP extends Net_SSH2 {
|
||||
*/
|
||||
function truncate($filename, $new_size)
|
||||
{
|
||||
$attr = pack('N3', NET_SFTP_ATTR_SIZE, 0, $new_size);
|
||||
$attr = pack('N3', NET_SFTP_ATTR_SIZE, $new_size / 0x100000000, $new_size);
|
||||
|
||||
return $this->_setstat($filename, $attr, false);
|
||||
}
|
||||
@ -1520,7 +1520,8 @@ class Net_SFTP extends Net_SSH2 {
|
||||
$i = 0;
|
||||
while ($sent < $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, $offset + $sent, strlen($temp), $temp);
|
||||
$subtemp = $offset + $sent;
|
||||
$packet = pack('Na*N3a*', strlen($handle), $handle, $subtemp / 0x100000000, $subtemp, strlen($temp), $temp);
|
||||
if (!$this->_send_sftp_packet(NET_SFTP_WRITE, $packet)) {
|
||||
fclose($fp);
|
||||
return false;
|
||||
@ -1650,7 +1651,7 @@ class Net_SFTP extends Net_SSH2 {
|
||||
|
||||
$size = (1 << 20) < $length || $length < 0 ? 1 << 20 : $length;
|
||||
while (true) {
|
||||
$packet = pack('Na*N3', strlen($handle), $handle, 0, $offset, $size);
|
||||
$packet = pack('Na*N3', strlen($handle), $handle, $offset / 0x100000000, $offset, $size);
|
||||
if (!$this->_send_sftp_packet(NET_SFTP_READ, $packet)) {
|
||||
if ($local_file !== false) {
|
||||
fclose($fp);
|
||||
@ -1904,11 +1905,8 @@ class Net_SFTP extends Net_SSH2 {
|
||||
// (0xFFFFFFFF bytes), anyway. as such, we'll just represent all file sizes that are bigger than
|
||||
// 4GB as being 4GB.
|
||||
extract(unpack('Nupper/Nsize', $this->_string_shift($response, 8)));
|
||||
if ($upper) {
|
||||
$attr['size'] = 0xFFFFFFFF;
|
||||
} else {
|
||||
$attr['size'] = $size < 0 ? ($size & 0x7FFFFFFF) + 0x80000000 : $size;
|
||||
}
|
||||
$attr['size'] = $upper ? 0x100000000 * $upper;
|
||||
$attr['size']+= $size < 0 ? ($size & 0x7FFFFFFF) + 0x80000000 : $size;
|
||||
break;
|
||||
case NET_SFTP_ATTR_UIDGID: // 0x00000002 (SFTPv3 only)
|
||||
$attr+= unpack('Nuid/Ngid', $this->_string_shift($response, 8));
|
||||
@ -2204,4 +2202,4 @@ class Net_SFTP extends Net_SSH2 {
|
||||
$this->pwd = false;
|
||||
parent::_disconnect($reason);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user