proglab/sftp-client-bundle

Sftp Client Bundle

Installs: 5

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 3

Forks: 1

Open Issues: 0

Type:symfony-bundle

v1.0.4 2021-06-02 15:18 UTC

This package is auto-updated.

Last update: 2024-10-29 05:54:07 UTC


README

A SFTP client

Installation

Open a command console, enter your project directory and execute:

composer require proglab/sftp-client-bundle

If you're not using symfony/flex, enable the bundle by adding it to the list of registered bundles in the config/bundles.php file of your project:

// config/bundles.php

return [
    // ...
    Proglab\SftpClientBundle\SftpClientBundle::class => ['all' => true],
];

Usage

Generals

Getting a SftpClient

You have two choices:

  1. Create the client manually, and pass it a logger:
use Proglab\SftpClientBundle\Service\SftpClient;
use Psr\Log\NullLogger;

$logger = new NullLogger();
$client = new SftpClient($logger);
  1. Get the client from Dependency Injection:
use Proglab\SftpClientBundle\Service\SftpClient;

class Service
{
    public function __construct(private SftpClient $client)
    {
    }
}

Connection

You must connect to a SFTP server.

You need the username, password, host and port (22 by default).

$client->connect('username', 'password', 'host', 22);

Deconnection

$client->deco();

List files

From remote directoty

List files in remote directory. The remote directory path must be absolute.

$files = $client->getRemoteListFiles('/var/www/');

From local directory

List files in local directory. The local directory path must be absolute.

$files = $client->getLocalListFiles('/var/www/');

Operations

Upload

Upload a file from local to remote dir:

$files = $client->upload($fileLocalPath, $fileRemotePath, $delete = true);

Download

Download a file from remote to local dir:

$files = $client->download($fileRemotePath, $fileLocalPath, $delete = true);

Sync local dir to remote

Synchronize local files to remote directory:

$files = $client->syncLocalDirToRemote($localDir, $remoteDir, $delete = true);

Sync remote dir to local

Synchronize remote files to local directory:

$files = $client->syncRemoteDirToLocal($remoteDir, $localDir, $delete = true);

Thanks

Many thanks to jmsche for his help