[英]How can I configure an SCP/SFTP file storage?
您需要為 Flysystem 安裝SFTP 驅動程序,Laravel 用於其文件系統服務的庫:
composer require league/flysystem-sftp
這是您可以調整的示例配置。 添加到config/filesystems.php 中的disks
陣列:
'sftp' => [
'driver' => 'sftp',
'host' => 'example.com',
'port' => 21,
'username' => 'username',
'password' => 'password',
'privateKey' => 'path/to/or/contents/of/privatekey',
'root' => '/path/to/root',
'timeout' => 10,
]
通過將以下代碼添加到AppServiceProvider
(或其他適當的服務提供者)的boot()
方法,使用新驅動程序擴展 Laravel 的文件系統:
use Storage;
use League\Flysystem\Filesystem;
use League\Flysystem\Sftp\SftpAdapter;
...
public function boot()
{
Storage::extend('sftp', function ($app, $config) {
return new Filesystem(new SftpAdapter($config));
});
}
然后你可以像使用本地文件系統一樣使用 Laravel 的 API:
Storage::disk('sftp')->put('path/filename.txt', $fileContents);
現在,官方文檔有 SFTP 連接的說明: https : //laravel.com/docs/8.x/filesystem#sftp-driver-configuration
SFTP: composer require league/flysystem-sftp "~1.0"
SFTP 驅動程序配置 Laravel 的 Flysystem 集成與 SFTP 配合得很好; 但是,框架的默認 filesystems.php 配置文件中不包含示例配置。 如果您需要配置 SFTP 文件系統,您可以使用下面的配置示例:
'sftp' => [
'driver' => 'sftp',
'host' => 'example.com',
'username' => 'your-username',
'password' => 'your-password',
// Settings for SSH key based authentication...
'privateKey' => '/path/to/privateKey',
'password' => 'encryption-password',
// Optional SFTP Settings...
// 'port' => 22,
// 'root' => '',
// 'timeout' => 30,
],
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.