LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 07-27-2004, 09:11 PM   #1
zoonalex
LQ Newbie
 
Registered: Aug 2003
Location: Mexico
Distribution: Fedora 7
Posts: 5

Rep: Reputation: 0
Question 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?
 
Old 07-28-2004, 12:28 PM   #2
shubb
Member
 
Registered: Oct 2003
Location: San Francisco
Distribution: Slackware 13.37
Posts: 150

Rep: Reputation: 16
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?

Last edited by shubb; 07-28-2004 at 12:32 PM.
 
Old 07-28-2004, 02:25 PM   #3
zoonalex
LQ Newbie
 
Registered: Aug 2003
Location: Mexico
Distribution: Fedora 7
Posts: 5

Original Poster
Rep: Reputation: 0
Question

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>";
exit;
}
else{
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 );
exit;
}
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?

Last edited by zoonalex; 07-28-2004 at 02:41 PM.
 
Old 07-29-2004, 11:51 AM   #4
shubb
Member
 
Registered: Oct 2003
Location: San Francisco
Distribution: Slackware 13.37
Posts: 150

Rep: Reputation: 16
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
shell script using /etc/cron.hourly to execute cron.php file? rioguia Programming 3 06-11-2008 08:09 AM
PHP can't execute shell command ! rome Programming 3 11-15-2005 12:46 PM
PHP can't execute shell command ! rome Programming 1 11-15-2005 09:12 AM
How to Execute PHP Script? notooth Linux - General 2 06-02-2005 05:43 AM
php/max time exceeded/execute via shell? jdc32 Linux - Software 0 01-31-2005 05:22 AM


All times are GMT -5. The time now is 05:59 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration