1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840
|
<?php
/**
* @author Andreas Fischer <bantu@phpbb.com>
* @copyright 2014 Andreas Fischer
* @license http://www.opensource.org/licenses/mit-license.html MIT License
*/
namespace phpseclib3\Tests\Functional\Net;
use phpseclib3\Net\SFTP;
use phpseclib3\Tests\PhpseclibFunctionalTestCase;
use PHPUnit\Framework\Attributes\Depends;
use PHPUnit\Framework\Attributes\Group;
class SFTPUserStoryTest extends PhpseclibFunctionalTestCase
{
protected static $scratchDir;
protected static $exampleData;
protected static $exampleDataLength;
protected static $buffer;
public static function setUpBeforeClass(): void
{
parent::setUpBeforeClass();
self::$scratchDir = uniqid('phpseclib-sftp-scratch-');
self::$exampleData = str_repeat('abcde12345', 1000);
self::$exampleDataLength = 10000;
}
public function testConstructor()
{
$sftp = new SFTP($this->getEnv('SSH_HOSTNAME'));
$this->assertIsObject(
$sftp,
'Could not construct NET_SFTP object.'
);
return $sftp;
}
/** @depends testConstructor */
#[Depends('testConstructor')]
public function testPasswordLogin($sftp)
{
$username = $this->getEnv('SSH_USERNAME');
$password = $this->getEnv('SSH_PASSWORD');
$this->assertTrue(
$sftp->login($username, $password),
'SSH2/SFTP login using password failed.'
);
return $sftp;
}
/** @depends testPasswordLogin */
#[Depends('testPasswordLogin')]
public function testPwdHome($sftp)
{
$this->assertEquals(
$this->getEnv('SSH_HOME'),
$sftp->pwd(),
'Failed asserting that pwd() returns home directory after login.'
);
return $sftp;
}
/** @depends testPwdHome */
#[Depends('testPwdHome')]
public function testMkDirScratch($sftp)
{
$dirname = self::$scratchDir;
$this->assertTrue(
$sftp->mkdir($dirname),
"Failed asserting that a new scratch directory $dirname could " .
'be created.'
);
$this->assertFalse(
$sftp->mkdir($dirname),
"Failed asserting that a new scratch directory $dirname could " .
'not be created (because it already exists).'
);
return $sftp;
}
/** @depends testMkDirScratch */
#[Depends('testMkDirScratch')]
public function testChDirScratch($sftp)
{
$this->assertTrue(
$sftp->chdir(self::$scratchDir),
sprintf(
'Failed asserting that working directory could be changed ' .
'to scratch directory %s.',
self::$scratchDir
)
);
$pwd = $sftp->pwd();
$this->assertStringStartsWith(
$this->getEnv('SSH_HOME'),
$pwd,
'Failed asserting that the home directory is a prefix of the ' .
'current working directory.'
);
$this->assertStringEndsWith(
self::$scratchDir,
$pwd,
'Failed asserting that the scratch directory name is a suffix ' .
'of the current working directory.'
);
return $sftp;
}
/** @depends testChDirScratch */
#[Depends('testChDirScratch')]
public function testStatOnDir($sftp)
{
$this->assertNotSame(
[],
$sftp->stat('.'),
'Failed asserting that the cwd has a non-empty stat.'
);
return $sftp;
}
public static function demoCallback($length)
{
$r = substr(self::$buffer, 0, $length);
self::$buffer = substr(self::$buffer, $length);
if (strlen($r)) {
return $r;
}
return null;
}
/** @depends testStatOnDir */
#[Depends('testStatOnDir')]
public function testPutSizeGetFile($sftp)
{
$this->assertTrue(
$sftp->put('file1.txt', self::$exampleData),
'Failed asserting that example data could be successfully put().'
);
$this->assertSame(
self::$exampleDataLength,
$sftp->filesize('file1.txt'),
'Failed asserting that put example data has the expected length'
);
$this->assertSame(
self::$exampleData,
$sftp->get('file1.txt'),
'Failed asserting that get() returns expected example data.'
);
$this->assertTrue(
$sftp->put('file1.txt', 'xxx', SFTP::RESUME),
'Failed asserting that an upload could be successfully resumed'
);
$this->assertSame(
self::$exampleDataLength + 3,
$sftp->filesize('file1.txt'),
'Failed asserting that put example data has the expected length'
);
$this->assertSame(
self::$exampleData . 'xxx',
$sftp->get('file1.txt'),
'Failed asserting that get() returns expected example data.'
);
return $sftp;
}
/** @depends testStatOnDir */
#[Depends('testStatOnDir')]
public function testPutSizeGetFileCallback($sftp)
{
self::$buffer = self::$exampleData;
$this->assertTrue(
$sftp->put('file1.txt', [__CLASS__, 'demoCallback'], $sftp::SOURCE_CALLBACK),
'Failed asserting that example data could be successfully put().'
);
$this->assertSame(
self::$exampleDataLength,
$sftp->filesize('file1.txt'),
'Failed asserting that put example data has the expected length'
);
$this->assertSame(
self::$exampleData,
$sftp->get('file1.txt'),
'Failed asserting that get() returns expected example data.'
);
return $sftp;
}
/** @depends testPutSizeGetFile */
#[Depends('testPutSizeGetFile')]
public function testTouch($sftp)
{
$this->assertTrue(
$sftp->touch('file2.txt'),
'Failed asserting that touch() successfully ran.'
);
$this->assertTrue(
$sftp->file_exists('file2.txt'),
'Failed asserting that touch()\'d file exists'
);
return $sftp;
}
/** @depends testTouch */
#[Depends('testTouch')]
public function testTruncate($sftp)
{
$this->assertTrue(
$sftp->touch('file3.txt'),
'Failed asserting that touch() successfully ran.'
);
$this->assertTrue(
$sftp->truncate('file3.txt', 1024 * 1024),
'Failed asserting that touch() successfully ran.'
);
$this->assertSame(
1024 * 1024,
$sftp->filesize('file3.txt'),
'Failed asserting that truncate()\'d file has the expected length'
);
return $sftp;
}
/**
* @group github850
*/
/** @depends testTruncate */
#[Depends('testTruncate')]
#[Group('github850')]
public function testChModOnFile($sftp)
{
$this->assertNotFalse(
$sftp->chmod(0755, 'file1.txt'),
'Failed asserting that chmod() was successful.'
);
return $sftp;
}
/** @depends testChModOnFile */
#[Depends('testChModOnFile')]
public function testChDirOnFile($sftp)
{
$this->assertFalse(
$sftp->chdir('file1.txt'),
'Failed to assert that the cwd cannot be changed to a file'
);
return $sftp;
}
/** @depends testChDirOnFile */
#[Depends('testChDirOnFile')]
public function testFileExistsIsFileIsDirFile($sftp)
{
$this->assertTrue(
$sftp->file_exists('file1.txt'),
'Failed asserting that file_exists() on example file returns true.'
);
$this->assertTrue(
$sftp->is_file('file1.txt'),
'Failed asserting that is_file() on example file returns true.'
);
$this->assertFalse(
$sftp->is_dir('file1.txt'),
'Failed asserting that is_dir() on example file returns false.'
);
return $sftp;
}
/** @depends testFileExistsIsFileIsDirFile */
#[Depends('testFileExistsIsFileIsDirFile')]
public function testFileExistsIsFileIsDirFileNonexistent($sftp)
{
$this->assertFalse(
$sftp->file_exists('file4.txt'),
'Failed asserting that a nonexistent file does not exist.'
);
$this->assertFalse(
$sftp->is_file('file4.txt'),
'Failed asserting that is_file() on nonexistent file returns false.'
);
$this->assertFalse(
$sftp->is_dir('file4.txt'),
'Failed asserting that is_dir() on nonexistent file returns false.'
);
return $sftp;
}
/** @depends testFileExistsIsFileIsDirFileNonexistent */
#[Depends('testFileExistsIsFileIsDirFileNonexistent')]
public function testSortOrder($sftp)
{
$this->assertTrue(
$sftp->mkdir('temp'),
"Failed asserting that a new scratch directory temp could " .
'be created.'
);
$sftp->setListOrder('filename', SORT_DESC);
$list = $sftp->nlist();
$expected = ['.', '..', 'temp', 'file3.txt', 'file2.txt', 'file1.txt'];
$this->assertSame(
$list,
$expected,
'Failed asserting that list sorted correctly.'
);
$sftp->setListOrder('filename', SORT_ASC);
$list = $sftp->nlist();
$expected = ['.', '..', 'temp', 'file1.txt', 'file2.txt', 'file3.txt'];
$this->assertSame(
$list,
$expected,
'Failed asserting that list sorted correctly.'
);
$sftp->setListOrder('size', SORT_DESC);
$files = $sftp->nlist();
$last_size = 0x7FFFFFFF;
foreach ($files as $file) {
if ($sftp->is_file($file)) {
$cur_size = $sftp->filesize($file);
$this->assertLessThanOrEqual(
$last_size,
$cur_size,
'Failed asserting that nlist() is in descending order'
);
$last_size = $cur_size;
}
}
return $sftp;
}
/** @depends testSortOrder */
#[Depends('testSortOrder')]
public function testResourceXfer($sftp)
{
$fp = fopen('res.txt', 'w+');
$sftp->get('file1.txt', $fp);
rewind($fp);
$sftp->put('file4.txt', $fp);
fclose($fp);
$this->assertSame(
self::$exampleData,
$sftp->get('file4.txt'),
'Failed asserting that a file downloaded into a resource and reuploaded from a resource has the correct data'
);
return $sftp;
}
/** @depends testResourceXfer */
#[Depends('testResourceXfer')]
public function testSymlink($sftp)
{
$this->assertTrue(
$sftp->symlink('file3.txt', 'symlink'),
'Failed asserting that a symlink could be created'
);
return $sftp;
}
/** @depends testSymlink */
#[Depends('testSymlink')]
public function testStatLstatCache($sftp)
{
$stat = $sftp->stat('symlink');
$lstat = $sftp->lstat('symlink');
$this->assertNotEquals(
$stat,
$lstat,
'Failed asserting that stat and lstat returned different output for a symlink'
);
return $sftp;
}
/** @depends testStatLstatCache */
#[Depends('testStatLstatCache')]
public function testLinkFile($sftp)
{
$this->assertTrue(
$sftp->is_link('symlink'),
'Failed asserting that symlink is a link'
);
$this->assertTrue(
$sftp->is_file('symlink'),
'Failed asserting that symlink is a file'
);
$this->assertFalse(
$sftp->is_dir('symlink'),
'Failed asserting that symlink is not a directory'
);
return $sftp;
}
/** @depends testLinkFile */
#[Depends('testLinkFile')]
public function testReadlink($sftp)
{
$this->assertIsString(
$sftp->readlink('symlink'),
'Failed asserting that a symlink\'s target could be read'
);
return $sftp;
}
/**
* @group github716
*/
/** @depends testReadlink */
#[Depends('testReadlink')]
#[Group('github716')]
public function testStatOnCWD($sftp)
{
$stat = $sftp->stat('.');
$this->assertIsArray(
$stat,
'Failed asserting that stat on . returns an array'
);
$lstat = $sftp->lstat('.');
$this->assertIsArray(
$lstat,
'Failed asserting that lstat on . returns an array'
);
return $sftp;
}
/**
* on older versions this would result in a fatal error
*
* @group github402
*/
/** @depends testStatOnCWD */
#[Depends('testStatOnCWD')]
#[Group('github402')]
public function testStatcacheFix($sftp)
{
// Name used for both directory and file.
$name = 'stattestdir';
$this->assertTrue($sftp->mkdir($name));
$this->assertTrue($sftp->is_dir($name));
$this->assertTrue($sftp->chdir($name));
$this->assertStringEndsWith(self::$scratchDir . '/' . $name, $sftp->pwd());
$this->assertFalse($sftp->file_exists($name));
$this->assertTrue($sftp->touch($name));
$this->assertTrue($sftp->is_file($name));
$this->assertTrue($sftp->chdir('..'));
$this->assertStringEndsWith(self::$scratchDir, $sftp->pwd());
$this->assertTrue($sftp->is_dir($name));
$this->assertTrue($sftp->is_file("$name/$name"));
$this->assertTrue($sftp->delete($name, true));
return $sftp;
}
/** @depends testStatcacheFix */
#[Depends('testStatcacheFix')]
public function testChDirUpHome($sftp)
{
$this->assertTrue(
$sftp->chdir('../'),
'Failed asserting that directory could be changed one level up.'
);
$this->assertEquals(
$this->getEnv('SSH_HOME'),
$sftp->pwd(),
'Failed asserting that pwd() returns home directory.'
);
return $sftp;
}
/** @depends testChDirUpHome */
#[Depends('testChDirUpHome')]
public function testFileExistsIsFileIsDirDir($sftp)
{
$this->assertTrue(
$sftp->file_exists(self::$scratchDir),
'Failed asserting that file_exists() on scratch dir returns true.'
);
$this->assertFalse(
$sftp->is_file(self::$scratchDir),
'Failed asserting that is_file() on example file returns false.'
);
$this->assertTrue(
$sftp->is_dir(self::$scratchDir),
'Failed asserting that is_dir() on example file returns true.'
);
return $sftp;
}
/** @depends testFileExistsIsFileIsDirDir */
#[Depends('testFileExistsIsFileIsDirDir')]
public function testTruncateLargeFile($sftp)
{
$filesize = (4 * 1024 + 16) * 1024 * 1024;
$filename = 'file-large-from-truncate-4112MiB.txt';
$this->assertTrue($sftp->touch($filename));
$this->assertTrue($sftp->truncate($filename, $filesize));
$this->assertSame($filesize, $sftp->filesize($filename));
return $sftp;
}
/** @depends testTruncateLargeFile */
#[Depends('testTruncateLargeFile')]
public function testRmDirScratch($sftp)
{
$this->assertFalse(
$sftp->rmdir(self::$scratchDir),
'Failed asserting that non-empty scratch directory could ' .
'not be deleted using rmdir().'
);
return $sftp;
}
/** @depends testRmDirScratch */
#[Depends('testRmDirScratch')]
public function testDeleteRecursiveScratch($sftp)
{
$this->assertTrue(
$sftp->delete(self::$scratchDir),
'Failed asserting that non-empty scratch directory could ' .
'be deleted using recursive delete().'
);
return $sftp;
}
/** @depends testDeleteRecursiveScratch */
#[Depends('testDeleteRecursiveScratch')]
public function testRmDirScratchNonexistent($sftp)
{
$this->assertFalse(
$sftp->rmdir(self::$scratchDir),
'Failed asserting that nonexistent scratch directory could ' .
'not be deleted using rmdir().'
);
return $sftp;
}
/**
* @group github706
*/
/** @depends testRmDirScratchNonexistent */
#[Depends('testRmDirScratchNonexistent')]
#[Group('github706')]
public function testDeleteEmptyDir($sftp)
{
$this->assertTrue(
$sftp->mkdir(self::$scratchDir),
'Failed asserting that scratch directory could ' .
'be created.'
);
$this->assertIsArray(
$sftp->stat(self::$scratchDir),
'Failed asserting that stat on an existent empty directory returns an array'
);
$this->assertTrue(
$sftp->delete(self::$scratchDir),
'Failed asserting that empty scratch directory could ' .
'be deleted using recursive delete().'
);
$this->assertFalse(
$sftp->stat(self::$scratchDir),
'Failed asserting that stat on a deleted directory returns false'
);
$this->assertFalse(
$sftp->delete(self::$scratchDir),
'Failed asserting that non-existent directory could not ' .
'be deleted using recursive delete().'
);
return $sftp;
}
/**
* @group github735
*/
/** @depends testDeleteEmptyDir */
#[Depends('testDeleteEmptyDir')]
#[Group('github735')]
public function testStatVsLstat($sftp)
{
$this->assertTrue($sftp->mkdir(self::$scratchDir));
$this->assertTrue($sftp->chdir(self::$scratchDir));
$this->assertTrue($sftp->put('text.txt', 'zzzzz'));
$this->assertTrue($sftp->symlink('text.txt', 'link.txt'));
$this->assertTrue($sftp->mkdir('subdir'));
$this->assertTrue($sftp->symlink('subdir', 'linkdir'));
$sftp->clearStatCache();
// pre-populate the stat cache
$sftp->nlist();
$stat = $sftp->stat('link.txt');
$this->assertSame($stat['type'], NET_SFTP_TYPE_REGULAR);
$stat = $sftp->lstat('link.txt');
$this->assertSame($stat['type'], NET_SFTP_TYPE_SYMLINK);
$stat = $sftp->stat('linkdir');
$this->assertSame($stat['type'], NET_SFTP_TYPE_DIRECTORY);
$stat = $sftp->lstat('link.txt');
$this->assertSame($stat['type'], NET_SFTP_TYPE_SYMLINK);
$sftp->disableStatCache();
$sftp->nlist();
$stat = $sftp->stat('link.txt');
$this->assertSame($stat['type'], NET_SFTP_TYPE_REGULAR);
$stat = $sftp->lstat('link.txt');
$this->assertSame($stat['type'], NET_SFTP_TYPE_SYMLINK);
$stat = $sftp->stat('linkdir');
$this->assertSame($stat['type'], NET_SFTP_TYPE_DIRECTORY);
$stat = $sftp->lstat('link.txt');
$this->assertSame($stat['type'], NET_SFTP_TYPE_SYMLINK);
$sftp->enableStatCache();
return $sftp;
}
/**
* @group github830
*/
/** @depends testStatVsLstat */
#[Depends('testStatVsLstat')]
#[Group('github830')]
public function testUploadOffsets($sftp)
{
$sftp->put('offset.txt', 'res.txt', SFTP::SOURCE_LOCAL_FILE, 0, 10);
$this->assertSame(
substr(self::$exampleData, 10),
$sftp->get('offset.txt'),
'Failed asserting that portions of a file could be uploaded.'
);
$sftp->put('offset.txt', 'res.txt', SFTP::SOURCE_LOCAL_FILE, self::$exampleDataLength - 100);
$this->assertSame(
substr(self::$exampleData, 10, -90) . self::$exampleData,
$sftp->get('offset.txt'),
'Failed asserting that you could upload into the middle of a file.'
);
return $sftp;
}
/** @depends testUploadOffsets */
#[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'));
return $sftp;
}
/**
* @group github999
*/
/** @depends testReadableWritable */
#[Depends('testReadableWritable')]
#[Group('github999')]
public function testExecNlist($sftp)
{
$sftp->enablePTY();
$sftp->exec('ping google.com -c 5');
sleep(5);
$sftp->nlist();
$this->assertTrue(true);
return $sftp;
}
/** @depends testExecNlist */
#[Depends('testExecNlist')]
public function testRawlistDisabledStatCache($sftp)
{
$this->assertTrue($sftp->mkdir(self::$scratchDir));
$this->assertTrue($sftp->chdir(self::$scratchDir));
$this->assertTrue($sftp->put('text.txt', 'zzzzz'));
$this->assertTrue($sftp->mkdir('subdir'));
$this->assertTrue($sftp->chdir('subdir'));
$this->assertTrue($sftp->put('leaf.txt', 'yyyyy'));
$this->assertTrue($sftp->chdir('../../'));
$list_cache_enabled = $sftp->rawlist('.', true);
$sftp->clearStatCache();
$sftp->disableStatCache();
$list_cache_disabled = $sftp->rawlist('.', true);
$this->assertEquals(
$list_cache_enabled,
$list_cache_disabled,
'The files should be the same regardless of stat cache'
);
return $sftp;
}
/** @depends testRawlistDisabledStatCache */
#[Depends('testRawlistDisabledStatCache')]
public function testChownChgrp($sftp)
{
$stat = $sftp->stat(self::$scratchDir);
$this->assertTrue($sftp->chown(self::$scratchDir, $stat['uid']));
$this->assertTrue($sftp->chgrp(self::$scratchDir, $stat['gid']));
$sftp->clearStatCache();
$stat2 = $sftp->stat(self::$scratchDir);
$this->assertSame($stat['uid'], $stat2['uid']);
$this->assertSame($stat['gid'], $stat2['gid']);
return $sftp;
}
/**
* @group github1934
*/
/** @depends testChownChgrp */
#[Depends('testChownChgrp')]
#[Group('github1934')]
public function testCallableGetWithLength($sftp)
{
$sftp->put('test.txt', 'zzzzz');
$sftp->get('test.txt', function ($data) {
}, 0, 1);
$this->assertTrue(true);
return $sftp;
}
/** @depends testPasswordLogin */
#[Depends('testPasswordLogin')]
public function testStatVfs($sftp)
{
$sftp->put('test.txt', 'aaaaa');
$stat = $sftp->statvfs('test.txt');
$this->assertArrayHasKey('bsize', $stat);
$this->assertArrayHasKey('frsize', $stat);
$this->assertArrayHasKey('blocks', $stat);
$this->assertArrayHasKey('bfree', $stat);
$this->assertArrayHasKey('bavail', $stat);
$this->assertArrayHasKey('files', $stat);
$this->assertArrayHasKey('ffree', $stat);
$this->assertArrayHasKey('favail', $stat);
$this->assertArrayHasKey('fsid', $stat);
$this->assertArrayHasKey('flag', $stat);
$this->assertArrayHasKey('namemax', $stat);
$this->assertSame(255, $stat['namemax']);
}
/** @depends testPasswordLogin */
#[Depends('testPasswordLogin')]
public function testPosixRename($sftp)
{
$sftp->put('test1.txt', 'aaaaa');
$sftp->put('test2.txt', 'bbbbb');
$sftp->posix_rename('test1.txt', 'test2.txt');
$this->assertSame('aaaaa', $sftp->get('test2.txt'));
}
}
|