-   Programming (
-   -   PHP -- How to execute a shell script from PHP using FTP functions?? (

zoonalex 07-27-2004 10:11 PM

PHP -- How to execute a shell script from PHP using FTP functions??
How to execute a shell script from PHP using FTP functions??

I want to execute a shell script from PHP, the shell script will be in a FTP server, so I need to execute it using the Ftp functions that come with PHP.
I' ve tried to do this, but I got a Denied Permission error. I don't know if this error comes from the FTP server or maybe because PHP can not do this kind of work.

Does anyone know if this can be done? :Pengy:

shubb 07-28-2004 01:28 PM

Can you post your php code? Can you also post the apache errors log too? Is the Access denied an error in the web page, or the logs?

I'm presuming that this ftp server is a different server, and not the same server as the web server, right?

Also, I think the problem may be that you're trying to execute a command through ftp. FTP is used for transferring files, not remote control/execution. Are you able to do get it to work if you use the normal ftp client and try to execute the script?

zoonalex 07-28-2004 03:25 PM

The error:
Warning: ftp_exec(): Permission denied. in /src/php/prueba/ftp_test.php on line 37.

My code:


$ftps = array( host => "localhost",
user => "ftp",
psswd => ""

//Openning a ftp connection
$conn = ftp_connect( $ftps["host"] );

if( !$conn ){
echo "FTP server connection error" . "<BR>";
echo"Connected to FTP Server" . "<BR>";

//Login to the FTP server.
@$result = ftp_login( $conn, $ftps["user"], $ftps["psswd"] );

if( !$result){
echo "The page couldn't log in as : " . $ftps["user"] . "<BR>";
ftp_quit( $conn );
echo "You are user: " . $ftps["user"] . "<BR>";

//Getting file's time from the FTP_Server.
$time = ftp_mdtm( $conn, "/alex/hola.txt" );
echo date("D d-M-Y -- H:i:s", $time) . "<BR>";

//Executing shell script.
//my_script is a shell script which only has an echo statement.

$res = ftp_exec($conn, "/src/shell_scripts/my_script");
echo "Script Shell result: " . $res;

ftp_quit( $conn );


I executed the same shell script using a ftp client and it did it, so I suppose that it will also execute using the FTP functions of PHP.

I configured PHP with --enable-safe-mode. Does it affect when I try to use ftp_exec() function?

shubb 07-29-2004 12:51 PM

What are the permissions of the file you are trying to excecute? Is the file world readable and excecutable?

Also, it looks like this ftp server is the same server as the webserver, right? You have the host set to localhost (unless that is a mod so we can't see the IP...) Why dont you use the exec() command to run the file directly, and not use ftp.

All times are GMT -5. The time now is 03:28 PM.