PHP code example of soarfreely / remote-file
1. Go to this page and download the library: Download soarfreely/remote-file library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
soarfreely / remote-file example snippets
namespace Soarfreely\RemoteFile\Test;
use League\Flysystem\FileNotFoundException;
use Soarfreely\RemoteFile\Config\Config;
use Soarfreely\RemoteFile\Exception\RemoteFileException;
use Soarfreely\RemoteFile\RemoteFiles;
',
'privateKey' => '',
'root' => '/sftp',
'timeout' => 10,
'directoryPerm' => 0755
];
$filenames = [
'sftp_demo_2020-01-01.txt',
'sftp_demo_2020-01-02.txt',
];
$client = null;
$handle = null;
try {
$config = Config::create($config);
$client = new RemoteFiles($config);
// 获取多个文件句柄
$handleList = $client->listHandlesByFilename($filenames);
print_r($handleList);
echo PHP_EOL;
// 获取指定文件句柄
$handle = $client->getFileHandle('sftp_demo_2020-01-01.txt');
print_r($handle);
echo PHP_EOL;
} catch (RemoteFileException $e) {
print_r($e);
} catch (FileNotFoundException $e) {
print_r($e);
}
// 获取行内容
if ($client instanceof RemoteFiles && is_resource($handle)) {
$lineGenerator = $client->getLine($handle, 'txt', "\t");
foreach ($lineGenerator as $line) {
print_r($line);
break;
}
}
}
}
$test = new Test();
$test->index();