Unexpected behavior when using phpseclib

I recently tried to implement the phpseclib library to log into the SFTP server, to list all the files in the directory and upload them. After downloading them, move them to another directory on the server.

I was not very lucky ... So, following the code directly from their site , but added a magazine.

set_include_path(get_include_path() . PATH_SEPARATOR . 'phpseclib');

require('Net\SSH2.php');
require('Crypt\RSA.php');   

define('NET_SSH2_LOGGING', 2);
$ssh = new Net_SSH2('host_name', 'port');
$key = new Crypt_RSA();
$key->loadKey(file_get_contents('path_to_rsa_file'));
if (!$ssh->login('username', $key)) {
  exit('Login Failed');
}

$ssh->exec("pwd");

This results in the following error:

Unable to request pseudo-terminal

Admittedly, this is an older version, I don’t know exactly which one, so I thought maybe I should update it. After you entered the latest version using the composer and ran the same code as above, I get no errors, but I get this in the logs:

<- NET_SSH2_MSG_USERAUTH_SUCCESS (since last: 0.1395, network: 0.1394s)

-> NET_SSH2_MSG_CHANNEL_OPEN (since last: 0.0006, network: 0.0005s)
00000000  00:00:00:07:73:65:73:73:69:6f:6e:00:00:00:00:7f  ....session.....
00000010  ff:ff:ff:00:00:40:00                             .....@.

<- NET_SSH2_MSG_CHANNEL_OPEN_CONFIRMATION (since last: 0.1232, network: 0.1231s)
00000000  00:00:00:00:00:00:00:00:ff:ff:ff:ff:00:00:80:00  ................

-> NET_SSH2_MSG_CHANNEL_REQUEST (since last: 0.0008, network: 0.0006s)
00000000  00:00:00:00:00:00:00:04:65:78:65:63:01:00:00:00  ........exec....
00000010  03:70:77:64                                      .pwd

<- NET_SSH2_MSG_CHANNEL_FAILURE (since last: 0.123, network: 0.1228s)
00000000  00:00:00:00                                      ....

- ? SFTP, " : ".

!

+1
1
0

Source: https://habr.com/ru/post/1621263/


All Articles