falc / flysystem-sftp-symlink-plugin
Sftp symlink plugin for Flysystem.
Installs: 12 922
Dependents: 0
Suggesters: 0
Security: 0
Stars: 3
Watchers: 2
Forks: 1
Open Issues: 0
Requires
- league/flysystem: ~1.0
- league/flysystem-sftp: ~1.0
This package is not auto-updated.
Last update: 2024-12-21 16:33:02 UTC
README
Requirements
- Flysystem >= 1.0.0
- flysystem-sftp >= 1.0.0
Installation
Using composer:
composer require falc/flysystem-sftp-symlink-plugin
Or add it manually:
{ "require": { "falc/flysystem-sftp-symlink-plugin": "1.*" } }
Usage
This plugin requires a Filesystem
instance using the Sftp adapter.
use Falc\Flysystem\Plugin\Symlink\Sftp as SftpSymlinkPlugin; use League\Flysystem\Adapter\Sftp as SftpAdapter; use League\Flysystem\Filesystem; $filesystem = new Filesystem(new SftpAdapter(array( 'host' => 'example.com', 'port' => 22, 'username' => 'username', 'password' => 'password', 'privateKey' => 'path/to/or/contents/of/privatekey', 'root' => '/', 'timeout' => 10 )));
Symlink
Use symlink($target, $symlink)
to create a symlink.
$filesystem->addPlugin(new SftpSymlinkPlugin\Symlink()); $success = $filesystem->symlink('/tmp/some/target', '/tmp/symlink');
DeleteSymlink
Use deleteSymlink($symlink)
to delete a symlink.
$filesystem->addPlugin(new SftpSymlinkPlugin\DeleteSymlink()); $success = $filesystem->deleteSymlink('/tmp/symlink');
IsSymlink
Use isSymlink($filename)
to check if a file exists and is a symlink.
$filesystem->addPlugin(new SftpSymlinkPlugin\IsSymlink()); $isSymlink = $filesystem->isSymlink('/tmp/symlink');
Full and relative paths
The above examples show how to create symlinks using /
as root and full paths. But it is possible to use relative paths too.
use Falc\Flysystem\Plugin\Symlink\Sftp as SftpSymlinkPlugin; use League\Flysystem\Adapter\Sftp as SftpAdapter; use League\Flysystem\Filesystem; $filesystem = new Filesystem(new SftpAdapter(array( 'host' => 'example.com', 'port' => 22, 'username' => 'username', 'password' => 'password', 'privateKey' => 'path/to/or/contents/of/privatekey', 'root' => '/home/falc', 'timeout' => 10 ))); $filesystem->addPlugin(new SftpSymlinkPlugin\Symlink()); $filesystem->addPlugin(new SftpSymlinkPlugin\IsSymlink()); $filesystem->addPlugin(new SftpSymlinkPlugin\DeleteSymlink()); // Result: /home/falc/flytest -> /home/falc/projects/cli/flytest $filesystem->symlink('projects/cli/flytest', 'flytest'); // It is possible to check it or delete it in the same way: $isSymlink = $filesystem->isSymlink('flytest'); $filesystem->deleteSymlink('flytest');