我有一个 txt 文件,其中存储了我的配置详细信息。
配置文件
10.xx.xx.xx
abc
P@ssword1
/home/user/myfolder
我想要这个文件详细信息来连接到远程机器。
<?php
$myfile="confg.txt";
$line=file($myfile);
$server = "$line[0]";
$username = "$line[1]";
$password = "$line[2]";
$connection = ssh2_connect($server, 22);
ssh2_auth_password($connection, $username, $password);
ssh2_exec($connection,"bash hello.sh");
?>
当我运行 php 文件时,出现以下错误:
PHP 警告:ssh2_auth_password():使用密码的 abc 身份验证失败
它似乎无法正确读取和获取文件。因为,我也试过这个,但得到了同样的错误。所以与密码无关,可能无法正确输入。
$server = "10.xx.xx.xx";
$username = "$line[1]";
$password = "P@ssword1";
请建议我从 txt 文件中提供详细信息的合适方法。谢谢!!