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
|
|
|
|
*/
|
|
|
|
|
2015-07-04 01:18:19 +02:00
|
|
|
use phpseclib\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()
|
|
|
|
{
|
|
|
|
$context = stream_context_create(array(
|
|
|
|
'sftp' => array('session' => $this->sftp),
|
|
|
|
));
|
|
|
|
$fp = fopen($this->buildUrl('fooo.txt'), 'wb', false, $context);
|
|
|
|
$this->assertTrue(is_resource($fp));
|
|
|
|
fclose($fp);
|
|
|
|
$this->assertSame(0, $this->sftp->size('fooo.txt'));
|
|
|
|
}
|
|
|
|
|
2016-04-10 18:30:59 +02:00
|
|
|
/**
|
|
|
|
* @group github778
|
|
|
|
*/
|
|
|
|
public function testFilenameWithHash()
|
|
|
|
{
|
|
|
|
$context = stream_context_create(array(
|
|
|
|
'sftp' => array('session' => $this->sftp),
|
|
|
|
));
|
|
|
|
$fp = fopen($this->buildUrl('te#st.txt'), 'wb', false, $context);
|
|
|
|
fputs($fp, 'zzzz');
|
|
|
|
fclose($fp);
|
|
|
|
|
|
|
|
$this->assertTrue(in_array('te#st.txt', $this->sftp->nlist()));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Tests connection reuse functionality same as ssh2 extension:
|
|
|
|
* {@link http://php.net/manual/en/wrappers.ssh2.php#refsect1-wrappers.ssh2-examples}
|
|
|
|
*/
|
|
|
|
public function testConnectionReuse()
|
|
|
|
{
|
|
|
|
$originalConnectionsCount = count(\phpseclib\Net\SSH2::getConnections());
|
|
|
|
$session = $this->sftp;
|
|
|
|
$dirs = scandir("sftp://$session/");
|
|
|
|
$this->assertCount($originalConnectionsCount, \phpseclib\Net\SSH2::getConnections());
|
|
|
|
$this->assertEquals(array('.', '..'), array_slice($dirs, 0, 2));
|
|
|
|
}
|
|
|
|
|
2015-06-25 00:15:19 +02:00
|
|
|
protected function buildUrl($suffix)
|
|
|
|
{
|
|
|
|
return sprintf(
|
|
|
|
'sftp://via-context/%s/%s',
|
|
|
|
$this->sftp->pwd(),
|
|
|
|
$suffix
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|