Skip to content

Simple wrapper for standard PHP functions to transfer files via SFTP

License

Notifications You must be signed in to change notification settings

nowiko/SFTPBundle

Repository files navigation

SensioLabsInsight Scrutinizer Code Quality Build Status Maintainability

SFTP Bundle

This bundle provides a simple interface for transfer files by SFTP protocol.

Installation

  1. Install the bundle using Composer:
 composer require nw/sftp-bundle
  1. Enable bundle in AppKernel.php
class AppKernel extends Kernel
{
  public function registerBundles()
  {
      return array(
          // ... other bundles
          new NW\SFTPBundle\NWSFTPBundle()
       );
   }
}

Usage

  1. Connect to the SFTP server:
   $sftp = $this->get('nw.sftp');
   $sftp->connect($host, $port);
   $sftp->login($username, $password);
   // or
   $sftp->loginWithKey($host, $username, $pubkeyfile, $privkeyfile, $passphrase = null);
  1. Use SFTP client to transfer files:
    $sftp->fetch('/path/to/remoteFile', '/path/to/localFile');
    // or
    $sftp->send('/path/to/localFile', '/path/to/remoteFile');
  1. From CLI could be used one of the following commands:
app/console nw:sftp:fetch /path/to/remoteFile /path/to/localFile # - copy files from a remote server to the local machine
# or
app/console nw:sftp:send /path/to/localFile /path/to/remoteFile # - copy files from a local machine to the remote server