使用 phpseclib 时的意外行为 [英] Unexpected behavior when using phpseclib
问题描述
我最近尝试实现 phpseclib 库以登录 SFTP 服务器以列出目录中的所有文件并下载它们.下载后,将它们移动到服务器上的不同目录.
I've recently tried to implement the phpseclib library to log into a SFTP server to list all the files in a directory and download them. After downloading them, move them to a different directory on the server.
我运气不好...所以直接从 他们的网站上遵循代码,但添加了日志记录.
I'm not having much luck... So following the code straight from their site, but added logging.
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");
这会导致以下错误:
Unable to request pseudo-terminal
诚然,这是一个较旧的版本,我不确定到底是哪个版本,所以我想也许我应该更新一下.通过 Composer 获取最新版本并运行与上述相同的代码后,我没有收到任何错误,但我在日志中看到了这一点:
Admittedly this is an older version, I'm not sure exactly which one, so I thought maybe I should update. After pulling in the latest version via composer, and running 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 类,但由于其他问题注意:连接过早关闭"而失败.
Any one have any ideas? I've also tried using the SFTP class, but it failed with other problems "Notice: Connection closed prematurely".
感谢您的帮助!
推荐答案
看起来服务器不支持 exec()
.read()
/write()
:
Looks like the server just doesn't support exec()
. You might have better luck with read()
/ write()
:
http://phpseclib.sourceforge.net/ssh/examples.html#interactive
至于 SFTP...我需要查看日志才能有任何想法.
As for SFTP... I'd need to see logs to have any ideas.
这篇关于使用 phpseclib 时的意外行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!