2015-06-25 00:15:19 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @author Andreas Fischer <bantu@phpbb.com>
|
|
|
|
* @copyright 2015 Andreas Fischer
|
|
|
|
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
|
|
|
*/
|
|
|
|
|
2019-11-07 06:41:40 +01:00
|
|
|
use phpseclib3\Net\SFTP\Stream;
|
2015-06-25 00:15:19 +02:00
|
|
|
|
|
|
|
class Functional_Net_SFTPStreamTest extends Functional_Net_SFTPTestCase
|
|
|
|
{
|
2015-07-17 13:36:18 +02:00
|
|
|
public static function setUpBeforeClass()
|
2015-07-04 01:18:19 +02:00
|
|
|
{
|
|
|
|
Stream::register();
|
|
|
|
parent::setUpBeforeClass();
|
|
|
|
}
|
|
|
|
|
2015-06-25 00:15:19 +02:00
|
|
|
public function testFopenFcloseCreatesFile()
|
|
|
|
{
|
2017-11-27 09:30:14 +01:00
|
|
|
$context = stream_context_create([
|
|
|
|
'sftp' => ['session' => $this->sftp],
|
|
|
|
]);
|
2015-06-25 00:15:19 +02:00
|
|
|
$fp = fopen($this->buildUrl('fooo.txt'), 'wb', false, $context);
|
2020-12-13 02:22:36 +01:00
|
|
|
$this->assertIsResource($fp);
|
2015-06-25 00:15:19 +02:00
|
|
|
fclose($fp);
|
2020-02-12 06:01:18 +01:00
|
|
|
$this->assertSame(0, $this->sftp->filesize('fooo.txt'));
|
2015-06-25 00:15:19 +02:00
|
|
|
}
|
|
|
|
|
2016-04-10 18:30:59 +02:00
|
|
|
/**
|
|
|
|
* @group github778
|
|
|
|
*/
|
|
|
|
public function testFilenameWithHash()
|
|
|
|
{
|
2017-11-27 09:30:14 +01:00
|
|
|
$context = stream_context_create([
|
|
|
|
'sftp' => ['session' => $this->sftp],
|
|
|
|
]);
|
2016-04-10 18:30:59 +02:00
|
|
|
$fp = fopen($this->buildUrl('te#st.txt'), 'wb', false, $context);
|
|
|
|
fputs($fp, 'zzzz');
|
|
|
|
fclose($fp);
|
|
|
|
|
2017-12-07 21:08:19 +01:00
|
|
|
$this->assertContains('te#st.txt', $this->sftp->nlist());
|
2016-04-10 18:30:59 +02:00
|
|
|
}
|
|
|
|
|
2016-04-30 23:23:35 +02:00
|
|
|
/**
|
|
|
|
* Tests connection reuse functionality same as ssh2 extension:
|
|
|
|
* {@link http://php.net/manual/en/wrappers.ssh2.php#refsect1-wrappers.ssh2-examples}
|
|
|
|
*/
|
|
|
|
public function testConnectionReuse()
|
|
|
|
{
|
2019-11-07 06:41:40 +01:00
|
|
|
$originalConnectionsCount = count(\phpseclib3\Net\SSH2::getConnections());
|
2016-04-30 23:23:35 +02:00
|
|
|
$session = $this->sftp;
|
|
|
|
$dirs = scandir("sftp://$session/");
|
2019-11-07 06:41:40 +01:00
|
|
|
$this->assertCount($originalConnectionsCount, \phpseclib3\Net\SSH2::getConnections());
|
2017-11-27 09:30:14 +01:00
|
|
|
$this->assertEquals(['.', '..'], array_slice($dirs, 0, 2));
|
2016-04-30 23:23:35 +02:00
|
|
|
}
|
|
|
|
|
2015-06-25 00:15:19 +02:00
|
|
|
protected function buildUrl($suffix)
|
|
|
|
{
|
|
|
|
return sprintf(
|
|
|
|
'sftp://via-context/%s/%s',
|
|
|
|
$this->sftp->pwd(),
|
|
|
|
$suffix
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|