我正在使用脚本使用带有密钥的 sftp 登录到服务器。使用脚本访问服务器时出现以下错误。错误如下:
: No such file or directory
./new.php: line 2: syntax error near unexpected token \`'SSH_HOST','
'/new.php: line 2: `define( 'SSH_HOST', 'IP_Address' );
请参阅下面我正在使用的脚本:
<?php
define( 'SSH_HOST', 'IP_Address' );
define( 'SSH_PORT', 7475 );
define( 'SSH_PUBLIC_KEY', '/home/test/test_sftp.pub' );
define( 'SSH_PRIVATE_KEY', '/home/test_sftp.ppk' );
define( 'SSH_USERNAME', 'test55' );
define( 'SSH_PASSWORD', 'lkdlkdsf' );
//define( 'SSH_USERNAME', 'test5654' );
//define( 'SSH_PASSWORD', 'dfsfsd45' );
set_include_path(get_include_path() . PATH_SEPARATOR . 'phpseclib');
include_once('Net/SSH2.php');
include_once('Net/SFTP.php');
include_once('Crypt/RSA.php');
include_once('Crypt/Hash.php');
include_once('Math/BigInteger.php');
$rsa = new Crypt_RSA();
//$pubKey = file_get_contents('id_rsa.pub');
//$rsa->setPublicKey($pubKey);
$priKey = file_get_contents(SSH_PRIVATE_KEY);
$rsa->loadKey($priKey);
$sftp = new Net_SFTP(SSH_HOST, SSH_PORT);
if (!$sftp->login(SSH_USERNAME, $rsa)) {
echo 'error:';
print_r($sftp->getLog());
exit("Login Failed\n");
}
echo $sftp->pwd() . "\r\n";
//$sftp->put('filename.ext', 'Hiiii!');