0

I'm trying to get a file from a remote host but it asks me the password and the script is supposed to run without me to type the password. How can I send the password? I have to use shell_exec.

<?php
    $command="sftp  user@ip adress";
    shell_exec($command);
?>
Syan Souza
  • 149
  • 12
  • Check the answers for this question http://stackoverflow.com/q/5386482/1301076 - the same applies here – rjdown Mar 05 '15 at 13:03
  • I can't install sshpass in this machine – Syan Souza Mar 05 '15 at 13:10
  • sshpass is just one of the options. Consider them all, at least one will be suitable. `expect` for example. (note that you will need to create a script and call that instead of sftp directly) – rjdown Mar 05 '15 at 14:06

1 Answers1

2

My recommendation: use something like phpseclib, a pure PHP SFTP implementation. eg.

<?php
include('Net/SFTP.php');

$sftp = new Net_SFTP('www.domain.tld');
if (!$sftp->login('username', 'password')) {
    exit('Login Failed');
}

// copies filename.remote to filename.local from the SFTP server
$sftp->get('filename.remote', 'filename.local');
?>
narswet
  • 36
  • 1