Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-31-2013, 10:28 PM   PM User | #1
zubat
New Coder

 
Join Date: Dec 2011
Posts: 15
Thanks: 1
Thanked 0 Times in 0 Posts
zubat is an unknown quantity at this point
PHP ssh2 ubuntu

Hello,

im trying some new stuff in php and one is ssh2 now to exec a shell script on my ubuntu server. The problem is that nothing happends, i have tried alot of scripts that i found on the internet and no one works . For the moment i got this script and wanna see if anyone know whats wrong.

PHP Code:
<?php
$connection 
ssh2_connect('IP'port);
ssh2_auth_password($connection'user''password');

$stream ssh2_exec($connection'/home/mc/start.sh');
?>
Just changed the connection things so i wont get hacked ^_^
zubat is offline   Reply With Quote
Old 02-01-2013, 12:01 AM   PM User | #2
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,752
Thanks: 4
Thanked 2,468 Times in 2,437 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
Assuming that IP and port are actually valid here.
Start by enabling your error reporting. Any of those methods could be failing, but you're not checking the results of them.
PHP Code:
ini_set('display_errors'1);
error_reporting(E_ALL); 
Next, handle the error checking on each:
PHP Code:
if ($con ssh2_connect('host'22))
{
    if (
ssh2_auth_password($con'user''password'))
    {
        
$stream ssh2_exec($con'/home/mc/start.sh');
    }
    else
    {
        print 
'Invalid username/password';
    }
}
else
{
    print 
'Failed to connect to host';

Does that produce either error message?
__________________
PHP Code:
header('HTTP/1.1 420 Enhance Your Calm'); 
Fou-Lu is offline   Reply With Quote
Old 02-01-2013, 01:05 AM   PM User | #3
zubat
New Coder

 
Join Date: Dec 2011
Posts: 15
Thanks: 1
Thanked 0 Times in 0 Posts
zubat is an unknown quantity at this point
Im getting a fatal error, Call to undefined function ssh2_connect() on line 6 and thats the
PHP Code:
if ($con ssh2_connect('213.67.233.164'22)) 
Okey i tried on both my home server and a webhotel, at the webhotel i got the error because they miss an ssh2 extension but at home i got it. I get no errors
at all. Just a white screen with nothing on it.

Last edited by zubat; 02-01-2013 at 01:40 AM..
zubat is offline   Reply With Quote
Old 02-01-2013, 02:52 AM   PM User | #4
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,752
Thanks: 4
Thanked 2,468 Times in 2,437 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
White screen would indicate with the above code that it executed properly. The undefined function indicates that the server isn't compiled with ssh2. The only real way around that is with socketing which is far less pleasant.
__________________
PHP Code:
header('HTTP/1.1 420 Enhance Your Calm'); 
Fou-Lu is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

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 On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 01:06 PM.


Advertisement
Log in to turn off these ads.