使用phpseclib SCP下载二进制文件时出现问题
我有一个小PHP脚本,用于从远程服务器下载文件 脚本如下所示:使用phpseclib SCP下载二进制文件时出现问题,php,download,scp,phpseclib,Php,Download,Scp,Phpseclib,我有一个小PHP脚本,用于从远程服务器下载文件 脚本如下所示: include('Net/SCP.php'); echo var_dump($ssh->exec('whoami')); // debug to test the ssh connection. returns "myuser" $scp = new Net_SCP($ssh); try{ $remotePath = '/home/user/test.txt'
include('Net/SCP.php');
echo var_dump($ssh->exec('whoami')); // debug to test the ssh connection. returns "myuser"
$scp = new Net_SCP($ssh);
try{
$remotePath = '/home/user/test.txt';
$localPath = '/tmp/myfile';
if (!$scp->get($remotePath, $localPath)) {
throw new Exception("Problems to get file");
}
} catch (Exception $e) {
echo "\n\n" . var_dump($e->getMessage()) . "\n\n";die;
}
Jul 27 15:22:58 localhost sshd[14101]: Accepted password for myuser from myip port 51740 ssh2
Jul 27 15:22:58 localhost sshd[14101]: pam_unix(sshd:session): session opened for user myuser by (uid=0)
Jul 27 15:22:58 localhost sshd[14103]: Received disconnect from myip port 51740:11:
Jul 27 15:22:58 localhost sshd[14103]: Disconnected from user myuser myip port 51740
中有一些问题,因此使用了非常类似的代码片段。
对于许多文件来说,它就像一个符咒,但对于某些二进制文件来说,它失败了($remotePath='/home/user/test.p12';
)
使用phpseclib下载二进制文件有任何已知限制吗(我在中没有找到任何限制)?如果不是,我做错了什么?我是不是忘了一些选择或者别的什么
作为旁注scpmyuser@serverip:/home/user/test.p12/tmp/teste.p12
在命令行中工作正常
在评论之后,我必须指出我的脚本失败了。station$scp->get($remotePath,$localPath
对我尝试的所有二进制文件返回false。这就是我现在所拥有的。
据我所知,phpseclib没有任何关于这些失败的详细日志
我的应用程序日志(nginx)没有显示任何特殊内容。在我的远程服务器(centOS)上访问日志。对于这些测试,我可以控制它,但这不是真实的场景。我得到如下信息:
include('Net/SCP.php');
echo var_dump($ssh->exec('whoami')); // debug to test the ssh connection. returns "myuser"
$scp = new Net_SCP($ssh);
try{
$remotePath = '/home/user/test.txt';
$localPath = '/tmp/myfile';
if (!$scp->get($remotePath, $localPath)) {
throw new Exception("Problems to get file");
}
} catch (Exception $e) {
echo "\n\n" . var_dump($e->getMessage()) . "\n\n";die;
}
Jul 27 15:22:58 localhost sshd[14101]: Accepted password for myuser from myip port 51740 ssh2
Jul 27 15:22:58 localhost sshd[14101]: pam_unix(sshd:session): session opened for user myuser by (uid=0)
Jul 27 15:22:58 localhost sshd[14103]: Received disconnect from myip port 51740:11:
Jul 27 15:22:58 localhost sshd[14103]: Disconnected from user myuser myip port 51740
PHP版本:7.3(该脚本也用于具有较旧版本的服务器)
本地服务器:Debian 10
远程服务器:CentOs 8
引发问题的有问题的文件是证书p12文件。我发现了问题,它比我想象的要简单得多。它只是一个权限问题(出于任何好的原因,我在没有读取权限的情况下将所有测试文件放在一个目录中) 我决定把这个答案留在这里,因为我认为这在phpseclib文档中并不清楚,但是'Net/SCP.php'只适用于具有读取权限的文件,因此,在下载之前,请确保文件是可读的,或者执行类似于
chmod o+r filename
的操作
问题中的代码段适用于二进制文件。“但失败”请提供更多详细信息。请您的问题更详细地描述您的实际问题。它是如何失败的?当您运行代码时会发生什么?您是否收到任何错误消息?他们说什么?@Sammitch和Kenster。我试图提供更多信息,但没有更多信息。我只是发现了问题。有时,只需写下问题它给了我答案。