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

Laravel 5.2: More SSH / SFTP Commands

1

Following 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 allowed. However, by accessing the underlying libraries, you can extend the functionality available to you.

For instance, I wanted to get the list of files on a remote SFTP server, but the SSH Facade in Laravel didn’t have this functionality. Digging into the source code revealed that the phpseclib library was being used, which has  a lot more supported functions.

The underlying functions can be accessed using:

SSH::getGateway()->getConnection()->function($params);

Where function is a supported phpseclib function, and $params are any parameters needed for the function.

Examples

Here are just some of the extra functionality you can achieve using the phpseclib library:

<?php
// get list of files / directories, returns array
SSH::getGateway()->getConnection()->nlist('.');
// get current working directory, returns string
SSH::getGateway()->getConnection()->pwd();
// check for directory, returns boolean
SSH::getGateway()->getConnection()->is_dir("Directory");
// check for file, returns boolean
SSH::getGateway()->getConnection()->is_file("Directory");
// change to directory, returns boolean
SSH::getGateway()->getConnection()->chdir("Directory");
view raw laravel_sftp.php hosted with ❤ by GitHub
Laravel 5, PHP, SFTP, SSH

One comment on “Laravel 5.2: More SSH / SFTP Commands”

  1. Joseph H. says:
    December 5, 2020 at 12:29 AM

    Thank you very much! Very usefull

    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

Subscribe for updates

Support Me

Buy Me a Coffee

PSN Profile

Tags

ACL Amazon Web Services Android Android 4.4 KitKat Android 5.0 Lollipop Apache Backup Bug Command Line Cordova cPanel / WHM Facebook Facebook Graph API Facebook PHP SDK 4.0 Facebook Social Plugins Fan Page Flash Flat File Geolocation Google Nexus 5 Hacking HTML5 iOS JavaScript jQuery Laravel 5 Linux Mac OS MongoDB NodeJS Parse PDF PHP Plugin Portfolio PS4 Review Security Server SSH SSL Sysadmin Tutorial WordPress WordPress Plugins

© 2011-2026 Niraj Shah
  • Blog
  • Portfolio
  • WordPress
  • About Me
  • Contact Me
  • Privacy Policy