I have installed the ssh2 extension and even have it enabled. i have also enabled openssl. Everything seems fine, but when i try to connect to a server i am getting ssh2_connect() unable to connect error. The server i am trying to access is accessible from my machine, i connected to the server via the terminal but when i run the script on my machine it is unable to connect to the server, any ideas what is going wrong here ?
I would appreciate it if you guys could point out som possible reasons that i can check/debug!
My script is like this:
$connection = ssh2_connect('shell.example.com', 22);
ssh2_auth_password($connection, 'username', 'password');
PS: i know there is a libary(phpseclib) that i can use, but i want to use ssh2 extension
Thanks :) !
Related
I tryed connect to Mlab with php by following code:
$connection = new MongoClient('mongodb://user:pass#ds051605.mlab.com:51605/db');
This code worked correctly in my system but didn't work in host and reterned Error 500 (my host doesn't support from mongo). What is the problem? Is there need to supporting mongo in host?
Additionaly, var_dump($connection) command doesn't show error.
I am using PHP , I want to connect to remote server in SFTP, but the website said:
Fatal error: Call to undefined function ssh2_connect() in D:\xampp\htdocs\dive\database.php on line 9
Can you tell me in detail how to do this? I tired
<?php
$connection = ssh2_connect('ftp.server.com', 22);
if (ssh2_auth_password($connection, 'username', 'password'))
echo "Authentication success";
else
echo "Authentication failure";
?>
But it doesn't work.
After I connect to the server, is there a difference if I want to insert some data to the table in it? Which function should I use?
Have you installed / verified via phpinfo() that ssh2 is installed?
Quick Google search seems to indicate it is not by default
PHP Install SSH2 on Windows machine
I cannot get my local environment, Win7 running easyPHP 12, to connect to my server, ubuntu 11.04.
I connect to my server via sftp with filezilla fine, i can connect to my server via ssh with putty fine... the server requires no keys at the moment just a uname and pword...
I don't get it, the details i am passing via the php script are exactly the same as the ones i pass from filezilla and putty.
This is the code stripped to the bare basic:
//inlcude the phpseclib path in the include array and include the ssh2 class
set_include_path( WEBROOT_PRIVATE.'scripts/phpseclib0.3.0' );
if(!include('Net/SSH2.php')){
echo 'Sorry failed to load SSH2 class';
br();
}
if(!include('Net/SFTP.php')){
echo 'Sorry failed to load SFTP class';
br();
}
$connection = new Net_SFTP( 'xx.xx.xx.xx', 'xx' );
echo 'ss';
$login = $connection->login( 'username', 'password');
exit();
And this is the response i am getting:
Notice: Cannot connect to xx.xx.xx.xx. Error 10060. A connection
attempt failed because the connected party did not properly respond
after a period of time, or established connection failed because
connected host has failed to respond. in
....\www_private\scripts\phpseclib0.3.0\Net\SSH2.php
on line 776 ss
Most likely server requires keyboard-interactive auth, while component tries password auth.
It's failing with fsockopen with the error that you're getting, which suggests to me it's not a phpseclib problem so much as a PHP one.
So the way SSH works is that the server sends a banner immediately to you when you try to connect. It does that for stackoverflow.com for example:
<?php
$fsock = fsockopen('www.stackoverflow.com', 22);
echo fgets($fsock, 1024);
When I run that script I get "SSH-2.0-OpenSSH_5.3" back.
My guess would be that if you update that PHP script to work with your server you'll get the same error message phpseclib is giving you.
I'm trying to connect to my local SQL Server 2008 R2 (have also tried it with 2005, same result exactly) with PHP. I'm using PHP 5.1 which still supports php_mssql and mssql_connect().
for some reason PHP just won't find my server, I can connect via ODBC flawlessly an that's fine, but I would like to connect to SQL Server directly.
I have connected PHP to SQL Server a million times on different servers, this one seems to be the only one giving me issue.
This is my little test code to try and get the connection working.
//define connection garbage
$db['hostname'] = "USER90C6\SQLEXPRESS";
$db['username'] = "user";
$db['password'] = "password";
$db['database'] = "kal_auth";
//connection string
$conn = mssql_connect($db['hostname'], $db['username'], $db['password']);
//does it work? :o
if($conn)
{
echo "works";
}
else
{
echo "fails";
}
The error this code produces:
Warning: mssql_connect() [function.mssql-connect]: Unable to connect to server: USER90C6\SQLEXPRESS in C:\xampp\htdocs\test.php on line 9
fails
Is there something seriously wrong with my setup? or am I missing something.
Did you enable TCP/IP on the server's configuration tool?
Is the firewall blocking any ports you might be using?
Are your MDAC (microsoft data access components) updated?
turn on mssql.secure_connection in php.ini
I think you don't miss anything.. Your connection string seems to be right (you receive a "Unable to connect" error..).
In my opinion, you problem can be a version incompatibility or a user privileges mistake. First of all: look at DLL driver you are using in PHP and check it's compatibility with you MSSQL version.
Maybe can be a good idea a fresh PHP install, with the latest stable release, if it is possible. Give a look at: http://www.php.net/manual/en/mssql.requirements.php
Good luck.
I have an secure FTP Server with the login details and from PHP, am trying to connect to that secure FTP Server using ftp_ssl_connect/ftp_connect and ftp_login function and passing all the parameters properly to the function but I am amazed to see that it does not connect.
If I try to connect to that secure FTP Server from command line using ssh than I am able to do so but when I am trying to connect through php code, it does not connect and so I am not sure why this is happening ?
Also what are the other ways to connect to Secure FTP Server using PHP ?
EDIT : I tried using ssh2_sftp but still I was not able to connect to secure FTP Server.
EDIT 2 : Are there any other ways to do SFTP with PHP, please advise.
Update : Added code which used ssh2_sftp to connect to secure FTP Server but it didn't worked and program died out with message Cannot connect to Server
<?php
$connection = ssh2_connect('www.server.com', 22);
ssh2_auth_password($connection, 'username', 'password');
$sftp = ssh2_sftp($connection) or die ("Cannot connect to server");
$stream = fopen("ssh2.sftp://$sftp/path/to/file", 'r');
?>
FTP/S (FTP over SSL) is an entirely different protocol than SFTP (FTP over SSH), and you can't use a SSL library to connect to an SFTP server (or vice versa).
I'm no PHP programmer, but it does seem some options to connect to an SSH server are natively available for your platform.
Like mdb said, you need to use the ssh2 extension in PHP. If you're using Linux, it's pretty simple as sudo pecl install ssh2. If you're on OS X you need to either do a svn checkout, or follow the instructions here: http://thirdpartycode.com/2010/01/installing-the-php-ssh2-extension-in-snow-leopard-10-6/
I've had quite a bit of success with phpseclib, a pure PHP SFTP implementation. Never mind the fact that the PECL extension is hard to install but it's also unreliable and not very portable.