Answer the question
In order to leave comments, you need to log in
How to run bat file on remote server using php?
Hello, how can I run a php bat file that is hosted on the server? SSH is configured on the server, but this code is not responsive at all. Through Pytty I normally connect via SSH.
$connection = ssh2_connect('1.2.3.4', 22);
if(ssh2_auth_password($connection, 'admin', 'pass'))
{
print_r("1");
}
else
{
print_r("2");
}
Answer the question
In order to leave comments, you need to log in
<?php
$config = array(
'ssh_ip' => '**********',
'ssh_port' => '**********',
'ssh_user' => '**********',
'ssh_pass' => '**********'
);
if ($sshConnect = ssh2_connect($config['ssh_ip'], $config['ssh_port'])) {
if (ssh2_auth_password($sshConnect, $config['ssh_user'], $config['ssh_pass'])) {
$cmd = 'start.bat';
ssh2_exec($sshConnect, 'cd /home/;' . $cmd . ';');
} else {
die('Невозможно установить соединение с физ. сервером');
}
} else {
die('Невозможно установить соединение с физ. сервером');
}
if you plan to run a sh script on the server,
then .
using php php.net/function.exec,
well, if you have ssh, it’s not at all clear why you need this, since there is a
standard method. https://disnetern.ru/ssh-on-remote-server/
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question