PHP code example of falc / flysystem-sftp-symlink-plugin

1. Go to this page and download the library: Download falc/flysystem-sftp-symlink-plugin 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/ */

    

falc / flysystem-sftp-symlink-plugin example snippets


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
)));

$filesystem->addPlugin(new SftpSymlinkPlugin\Symlink());

$success = $filesystem->symlink('/tmp/some/target', '/tmp/symlink');

$filesystem->addPlugin(new SftpSymlinkPlugin\DeleteSymlink());

$success = $filesystem->deleteSymlink('/tmp/symlink');

$filesystem->addPlugin(new SftpSymlinkPlugin\IsSymlink());

$isSymlink = $filesystem->isSymlink('/tmp/symlink');

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');