This bundle provides a simple interface for transfer files by SFTP protocol.
- Install the bundle using Composer:
composer require nw/sftp-bundle
- Enable bundle in
AppKernel.php
class AppKernel extends Kernel
{
public function registerBundles()
{
return array(
// ... other bundles
new NW\SFTPBundle\NWSFTPBundle()
);
}
}
- 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);
- Use SFTP client to transfer files:
$sftp->fetch('/path/to/remoteFile', '/path/to/localFile');
// or
$sftp->send('/path/to/localFile', '/path/to/remoteFile');
- 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