R
R
RaTeNs2017-07-25 21:13:27
PHP
RaTeNs, 2017-07-25 21:13:27

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

2 answer(s)
W
w0key, 2017-07-25
@w0key

<?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('Невозможно установить соединение с физ. сервером');
}

V
Viktor Taran, 2017-07-26
@shambler81

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 question

Ask a Question

731 491 924 answers to any question