Web Niraj
  • Facebook
  • Flickr
  • Github
  • Linkedin
  • Twitter
  • YouTube
Online portfolio, code examples and developer blog
  • About
  • Contact
  • Portfolio
  • WordPress
Search the site...
  • Home
  • Blog
  • Laravel 5.2: Running SSH / SFTP Commands In Your Scripts

Laravel 5.2: Running SSH / SFTP Commands In Your Scripts

1

Recently, I had to create a Laravel Artisan script that would log into a SFTP server, check if a certain file exists, and then upload / override the file. To achieve this, I used the SSH library from LaravelCollective. This tutorial covers how to log into a remote server using SSH / SFTP and upload or download files.

Installation

The first step is to use composer to install the SSH library from LaravelCollective. You can achieve this by running the following command:

composer require "laravelcollective/remote":"^5.2.0"

The next step is to update the providers and alias in config/app.php. Add the following line to the providers array:

Collective\Remote\RemoteServiceProvider::class

And add the following line to the aliases array:

'SSH' => Collective\Remote\RemoteFacade::class

Finally, publish the config file using the artisan command:

php artisan vendor:publish --provider="Collective\Remote\RemoteServiceProvider"

Edit the config/remote.php with your required settings and you’re ready to go. For example, your configuration could look like:

Usage

Once setup, running commands is easy. For some examples, see:

In addition to exists, put, run and get, other commands exist in the SSH library. For example, you can define a sequence of commands, and run them as a task. Be sure to check out the LaravelCollective SSH documentation for other examples.

Laravel 5, PHP, SFTP, SSH

One comment on “Laravel 5.2: Running SSH / SFTP Commands In Your Scripts”

  1. Laravel 5.2: More SSH / SFTP Commands | Web Niraj says:
    May 5, 2017 at 2:56 PM

    […] on from my previous tutorial on writing code to access SSH / SFTP servers, I recently found that the SSH library from LaravelCollective uses was quite limited in what it […]

    Reply

Leave a Reply Cancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

StackExchange / StackOverflow

profile for Niraj Shah on Stack Exchange, a network of free, community-driven Q&A sites

PSN Profile

Tags

Amazon Web Services Android Android 4.4 KitKat Android 5.0 Lollipop Apache API Application Backup Bug Command Line Cordova Example Facebook Facebook Graph API Facebook PHP SDK 4.0 Facebook Social Plugins Fan Page Flash Geolocation Google Nexus 5 Google Nexus One Hacking HTML5 Image Manipulation iOS iPhone JavaScript jQuery Laravel 5 Linux NodeJS Parse PDF PHP Plugin Portfolio Review Security Server SSH SSL Sysadmin Tutorial WordPress WordPress Plugins
© 2011-2022 Niraj Shah
  • Blog
  • Portfolio
  • WordPress
  • About Me
  • Contact Me
  • Privacy Policy
Privacy & Cookies: This site uses cookies. By continuing to use this website, you agree to their use.
To find out more, including how to control cookies, see here: Privacy Policy