| @@ 11-45 (lines=35) @@ | ||
| 8 | use Symfony\Component\Console\Input\InputInterface; |
|
| 9 | use Symfony\Component\Console\Output\OutputInterface; |
|
| 10 | ||
| 11 | class FetchFromCommand extends ContainerAwareCommand |
|
| 12 | { |
|
| 13 | protected function configure() |
|
| 14 | { |
|
| 15 | $this |
|
| 16 | ->setName('sf2h:sftp:fetchFrom') |
|
| 17 | ->setDefinition(array( |
|
| 18 | new InputArgument('remoteFile', InputArgument::REQUIRED, 'Full path to remote file'), |
|
| 19 | new InputArgument('localFile', InputArgument::REQUIRED, 'Full path to local file') |
|
| 20 | )) |
|
| 21 | ->setDescription('Copy file from remote SFTP server to local machine') |
|
| 22 | ->setHelp(" |
|
| 23 | The <info>./app/console sftp:copy</info> command copies file from remote SFTP server to your local machine by specified path: |
|
| 24 | Command example: |
|
| 25 | <info>./app/console sftp:copy /path/to/remoteFile.txt /path/to/localFile.txt</info> |
|
| 26 | "); |
|
| 27 | } |
|
| 28 | ||
| 29 | /** |
|
| 30 | * {@inheritdoc} |
|
| 31 | */ |
|
| 32 | protected function execute(InputInterface $input, OutputInterface $output) |
|
| 33 | { |
|
| 34 | /** @var SFTP $sftp */ |
|
| 35 | $sftp = $this->get('sftp'); |
|
| 36 | ||
| 37 | try { |
|
| 38 | $output->writeln('Started fetching file from remote SFTP server.'); |
|
| 39 | $sftp->fetchFrom($input->getArgument('remoteFile'), $input->getArgument('localFile')); |
|
| 40 | $output->writeln('Successful file transfer from the SFTP server.'); |
|
| 41 | } catch (\Exception $e) { |
|
| 42 | $output->writeln('File transfer failed.'); |
|
| 43 | } |
|
| 44 | } |
|
| 45 | } |
|
| 46 | ||
| @@ 11-45 (lines=35) @@ | ||
| 8 | use Symfony\Component\Console\Input\InputInterface; |
|
| 9 | use Symfony\Component\Console\Output\OutputInterface; |
|
| 10 | ||
| 11 | class SendToCommand extends ContainerAwareCommand |
|
| 12 | { |
|
| 13 | protected function configure() |
|
| 14 | { |
|
| 15 | $this |
|
| 16 | ->setName('sf2h:sftp:sendTo') |
|
| 17 | ->setDefinition(array( |
|
| 18 | new InputArgument('localFile', InputArgument::REQUIRED, 'Full path to local file'), |
|
| 19 | new InputArgument('remoteFile', InputArgument::REQUIRED, 'Full path to remote file') |
|
| 20 | )) |
|
| 21 | ->setDescription('Send file to remote SFTP server from local machine') |
|
| 22 | ->setHelp(" |
|
| 23 | The <info>./app/console sftp:send</info> command copies file to remote SFTP server from your local machine by specified path: |
|
| 24 | Command example: |
|
| 25 | <info>./app/console sftp:send /path/to/localFile.txt /path/to/remoteFile.txt</info> |
|
| 26 | "); |
|
| 27 | } |
|
| 28 | ||
| 29 | /** |
|
| 30 | * {@inheritdoc} |
|
| 31 | */ |
|
| 32 | protected function execute(InputInterface $input, OutputInterface $output) |
|
| 33 | { |
|
| 34 | /** @var SFTP $sftp */ |
|
| 35 | $sftp = $this->get('sftp'); |
|
| 36 | ||
| 37 | try { |
|
| 38 | $output->writeln('Started sending file to remote SFTP server.'); |
|
| 39 | $sftp->sendTo($input->getArgument('localFile'), $input->getArgument('remoteFile')); |
|
| 40 | $output->writeln('Successful sending file to the SFTP server.'); |
|
| 41 | } catch (\Exception $e) { |
|
| 42 | $output->writeln('File transfer failed.'); |
|
| 43 | } |
|
| 44 | } |
|
| 45 | } |
|
| 46 | ||