run a from php / apache where sftp perform connection and upload

June 17, 2018 103 views

Hi All,
assume that I have a that runs perfectly if launched from a root shell.

sftp -oPort=22 user@localhost<<EOF
put /var/www/html/xml/file.xml /var/www/html/destination/file.xml

what I need is to run this script from php / apache, I've just try a lot and what give me the possibility to see something of what happen is a code like that :

$cmd = '/bin/sh /var/www/html/';

    if(exec("$cmd  2>&1", $output, $return_var)) {
    $upl.= "<br>";

I receive that :
Array ( [0] => Could not create directory '/usr/share/httpd/.ssh'. [1] => Host key verification failed. [2] => Couldn't read packet: Connection reset by peer ) 255

note the my key is just accept from the destination server because I can run the script in shell by root and I'm not sure to make something bad making the .ssh dir onto /usr/share/httpd/ where the sys after can make the know_hosts because in all the case in local continue to not work.

I think this is not the exact approach in CentOS
suggestions ?
always thanks

Be the first one to answer this question.