D
D
Dmitry2015-10-20 14:31:02
linux
Dmitry, 2015-10-20 14:31:02

How to mount virtual disk via SSHFS using PHP?

How to mount virtual disk via SSHFS using PHP ?
SERVER_IP - IP of the server I'm connecting to.
PASSWORD - the actual password of the remote user.
/mnt/ssh_drive - path to mount.
Through the console I do this -

echo PASSWORD | sshfs -C -p 22 -o allow_other [email protected]_IP:/ /mnt/ssh_drive -o password_stdin

In PHP code at execution
shell_exec("echo PASSWORD | sshfs -C -p 22 -o allow_other [email protected]_IP:/ /mnt/ssh_drive -o password_stdin")
Nothing happens.
I also tried to access the sh script -
#!/bin/bash

echo 'PASSWORD' | sshfs -C -p 22 -o allow_other [email protected]_IP:/ /mnt/ssh_drive -o password_stdin

OS: Debian 7.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Maxim Smirnov, 2015-10-20
@MaxiStyle

php.net/manual/en/function.shell-exec.php read "Remarks".
try another function instead of shell_exec, for example system or exec
I use quotes for such operations

$x = `echo 'PASSWORD' | sshfs -C -p 22 -o allow_other [email protected]_IP:/ /mnt/ssh_drive -o password_stdin`;
echo $x;

V
Victor Taran, 2015-10-30
@shambler81

Of course, nothing will happen to you,
and for this you will have to understand from which user your php is running and is he allowed to mount something at all?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question