mirror of
https://github.com/danog/tgseclib.git
synced 2024-12-02 09:37:45 +01:00
Merge branch '2.0'
This commit is contained in:
commit
43d68c6619
@ -2337,6 +2337,76 @@ class SFTP extends SSH2
|
|||||||
return $result === NET_SFTP_TYPE_SYMLINK;
|
return $result === NET_SFTP_TYPE_SYMLINK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tells whether a file exists and is readable
|
||||||
|
*
|
||||||
|
* @param string $path
|
||||||
|
* @return bool
|
||||||
|
* @access public
|
||||||
|
*/
|
||||||
|
function is_readable($path)
|
||||||
|
{
|
||||||
|
$path = $this->_realpath($path);
|
||||||
|
|
||||||
|
$packet = pack('Na*N2', strlen($path), $path, NET_SFTP_OPEN_READ, 0);
|
||||||
|
if (!$this->_send_sftp_packet(NET_SFTP_OPEN, $packet)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$response = $this->_get_sftp_packet();
|
||||||
|
switch ($this->packet_type) {
|
||||||
|
case NET_SFTP_HANDLE:
|
||||||
|
return true;
|
||||||
|
case NET_SFTP_STATUS: // presumably SSH_FX_NO_SUCH_FILE or SSH_FX_PERMISSION_DENIED
|
||||||
|
return false;
|
||||||
|
default:
|
||||||
|
user_error('Expected SSH_FXP_HANDLE or SSH_FXP_STATUS');
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tells whether the filename is writable
|
||||||
|
*
|
||||||
|
* @param string $path
|
||||||
|
* @return bool
|
||||||
|
* @access public
|
||||||
|
*/
|
||||||
|
function is_writable($path)
|
||||||
|
{
|
||||||
|
$path = $this->_realpath($path);
|
||||||
|
|
||||||
|
$packet = pack('Na*N2', strlen($path), $path, NET_SFTP_OPEN_WRITE, 0);
|
||||||
|
if (!$this->_send_sftp_packet(NET_SFTP_OPEN, $packet)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$response = $this->_get_sftp_packet();
|
||||||
|
switch ($this->packet_type) {
|
||||||
|
case NET_SFTP_HANDLE:
|
||||||
|
return true;
|
||||||
|
case NET_SFTP_STATUS: // presumably SSH_FX_NO_SUCH_FILE or SSH_FX_PERMISSION_DENIED
|
||||||
|
return false;
|
||||||
|
default:
|
||||||
|
user_error('Expected SSH_FXP_HANDLE or SSH_FXP_STATUS');
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tells whether the filename is writeable
|
||||||
|
*
|
||||||
|
* Alias of is_writable
|
||||||
|
*
|
||||||
|
* @param string $path
|
||||||
|
* @return bool
|
||||||
|
* @access public
|
||||||
|
*/
|
||||||
|
function is_writeable($path)
|
||||||
|
{
|
||||||
|
return $this->is_writable($path);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets last access time of file
|
* Gets last access time of file
|
||||||
*
|
*
|
||||||
|
@ -688,5 +688,27 @@ class Functional_Net_SFTPUserStoryTest extends PhpseclibFunctionalTestCase
|
|||||||
$sftp->get('offset.txt'),
|
$sftp->get('offset.txt'),
|
||||||
'Failed asserting that you could upload into the middle of a file.'
|
'Failed asserting that you could upload into the middle of a file.'
|
||||||
);
|
);
|
||||||
|
|
||||||
|
return $sftp;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @depends testUploadOffsets
|
||||||
|
*/
|
||||||
|
public function testReadableWritable($sftp)
|
||||||
|
{
|
||||||
|
$sftp->chmod(0000, 'offset.txt');
|
||||||
|
$this->assertFalse($sftp->is_writable('offset.txt'));
|
||||||
|
$this->assertFalse($sftp->is_writeable('offset.txt'));
|
||||||
|
$this->assertFalse($sftp->is_readable('offset.txt'));
|
||||||
|
|
||||||
|
$sftp->chmod(0777, 'offset.txt');
|
||||||
|
$this->assertTrue($sftp->is_writable('offset.txt'));
|
||||||
|
$this->assertTrue($sftp->is_writeable('offset.txt'));
|
||||||
|
$this->assertTrue($sftp->is_readable('offset.txt'));
|
||||||
|
|
||||||
|
$this->assertFalse($sftp->is_writable('nonexistantfile.ext'));
|
||||||
|
$this->assertFalse($sftp->is_writeable('nonexistantfile.ext'));
|
||||||
|
$this->assertFalse($sftp->is_readable('nonexistantfile.ext'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user