LaravelCollective / remote

Remote SSH Access for the Laravel Framework
MIT License
274 stars 105 forks source link

Unable to connect to remote server - Laravel 4.1 #50

Closed qannoufoualid closed 6 years ago

qannoufoualid commented 7 years ago

I want to execute some commands in a remote server using SSH. This is my configuration :

'connections' => [
    'production' => [
        'host'      => '172.55.81.20',
        'username'  => 'user',
        'password'  => '',
        'key'       => 'C:\cygwin64\home\oqannouf\.ssh\id_rsa'
    ]
]

I tried this : SSH::into('production')->run(['ls']); but i get the following error: Unable to connect to remote server with no additional informations explaining why it doesn't work. Note:

stidges commented 7 years ago

Are you still experiencing this issue?

qannoufoualid commented 7 years ago

After reading and debugging the code of the API (Yeah I know I suffered a lot). This API unfortunately requires FTP server to be running in the target server :\ which make no sens. So i got rid of that API and used the Pure-PHP implementation of SSHv2. This is a the class I created :

<?php namespace App\Services;

use SSH;

class SSHService {

public function execute(array $serverData, array $commands){

    $host = $serverData['host'];
    $port = $serverData['port'];
    $userName = $serverData['userName'];
    $password = $serverData['password'];

    $ssh = new \Net_SSH2($host);
    if (!$ssh->login($userName, $password)) {
        throw new \Exception('Unable to connect to server');
    }

    $output = '';

    foreach ($commands as $command){
        $output.= $ssh->exec($command);
    }

    return trim($output);
}

}

stidges commented 7 years ago

Yeah I'm not sure why a new SFTP instance is always created. Maybe we should implement some sort of driver configuration where a user is able to set driver to 'sftp' or 'ssh' and separate the two gateways

qannoufoualid commented 7 years ago

Yes, that's gonna be better. because there is no need to use FTP in case you want to use only SSH requests.