Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel SSH on Windows Server

I have a Laravel 4.2 project hosted on one server (Server A), and I need to be able to upload files from this application and the files be transferred to a Windows server which is on the same local network (Server B).

I have installed OpenSSH on the Windows server and started the service. I can confirm that this is working because I can connect successfully in a terminal on Server A.

In the Laravel project I have created the connection in the app/config/remote.php file.

But when I try to run a command in the Laravel project on Server A by using the following code:

SSH::into('ServerB')->run(['IF EXIST folder (echo YES) ELSE (echo NO)'], function($line){
    echo $line.PHP_EOL;
});

I get the following error:

unpack(): Type N: not enough input, need 4, have 1

I'm receiving this error for every command I try to run on Server B. Strangely, if I try to use the same code but point it to a Linux server, the code works fine. This would lead me to believe that the SSH server is probably set up incorrectly on Server B, but the fact that I can connect via SSH to Server B from Server A in a terminal window confuses the whole matter!

Does anyone know the meaning of the error I'm receiving?

like image 724
Dan Johnson Avatar asked Feb 03 '16 14:02

Dan Johnson


3 Answers

This is likely to be an issue with phpseclib. Check if you have the latest version installed, update if possible.

like image 158
bogl Avatar answered Nov 20 '22 22:11

bogl


Laravel 4.2's SSH is Facade that will resolve to Illuminate\Remote\RemoteManager. Its into() method will return Illuminate\Remote\Connection instance which then use SecLibGateway instance that encapsulate phpseclib library. SecLibGateway will return instance of phpseclib's System_SSH_Agent (see SSH_Agent.php in vendor/phpseclib/phpseclib/phpseclib/System directory in Laravel 4.2 installation). Inside System_SSH_Agent's constructor, at line 248:

$this->fsock = fsockopen('unix://' . $address, 0, $errno, $errstr);

It opens socket connection to unix://. OP said SSH works in Linux server but not in Windows server. I believe this may be the culprit. There are few calls to PHP's unpack() function such as at line 274:

$length = current(unpack('N', fread($this->fsock, 4)));

It calls unpack() with type N with 4 number required input. Somehow fsock is not valid and that cause error message to occured.

like image 36
Zamrony P. Juhara Avatar answered Nov 20 '22 20:11

Zamrony P. Juhara


It seems this kind of errors appears when "the warning appears when the input data is not correct" cfr this post

This could be due to a setting in php.ini, ie "magic_quotes_runtime works by adding backslashes in content read from external sources, like textfiles, effectively destroying binary input like an .mo-file, and also destroying configuration-settings read from the database..." cfr this post

like image 1
user1747036 Avatar answered Nov 20 '22 22:11

user1747036