Question
run a script.sh from php / apache where sftp perform connection and upload
Hi All,
assume that I have a script.sh that runs perfectly if launched from a root shell.
#!/usr/bin/sh
sftp -oPort=22 user@localhost<<EOF
put /var/www/html/xml/file.xml /var/www/html/destination/file.xml
exit
EOF
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/script.sh';
if(exec("$cmd 2>&1", $output, $return_var)) {
print_r($output);
$upl.= "<br>";
print_r($return_var);
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
Gio
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
×