When I' m trying to connect Sftp from my joomla site
its not connecting:
$c = ftp_connect('ftp.xyz.com') or die("Can't connect");
ftp_login($c, 'username' , 'pwd') or die("Can't login");
in this case msg showing Can't connect
I also tried this code
$connection = ssh2_connect('ftp.xyz.com', 22);
if (!$connection) die('Connection failed');
in this case no error msg showing
Please help me, if there is a proper solution help me please.
Thanks
ftp_connect() uses FTP, not SFTP. They're very different. So if your host is providing only SFTP, then no, that function won't work! SFTP is explained in more detail here:
http://en.wikipedia.org/wiki/SSH_File_Transfer_Protocol
ssh2_connect() is the right connection method to use, which is why it's probably working. You can see all the SSH2 functions available in PHP here:
http://php.net/manual/en/ref.ssh2.php
You'll probably be most interested in ssh2_scp_recv() and ssh2_scp_send() (for getting and sending files).
Related
In PHP, I cannot even get the SFTP connection to work. I have tried to use the native SFTP functionality (ssh_connect), and it fails to connect. I have also tried to use phpseclib, but it fails as well. Neither of my aforementioned attempts have provided much in the way of log info.
The native code:
if (!function_exists('ssh2_connect')) {
echo "dll not loaded properly"; //never see this, so I know it works
return false;
}
$connection = ssh2_connect('sftp.example.com', 22);
ssh2_auth_password($connection, 'username', 'password');
$sftp = ssh2_sftp($connection);
phpseclib library code:
include('Net/SFTP.php');
$sftp = new Net_SFTP('sftp.example.com');
if (!$sftp->login('username', 'password')) {
exit('Login Failed');
}
I have also tried to track all of the transactions via Fiddler to see if I at least see a connection being made, and I do see an error in the browser (below) that from googling may mean that a connection was made to the server, but no responses.
[Fiddler] ReadResponse() failed: The server did not return a complete response for this request. Server returned 17139 bytes.
Why am I able to connect to the URL with the username and password via FIleZilla, but not from within php? Do I need some other DLLs in PHP's /ext folder (e.g. php_openssl.dll, etc.)?
Thanks,
Sean
I have bought a Web Hosting on Godaddy. I worked on my website with WampServer and the following code worked good. Now, with Godaddy it doesn't work.
#mysql_connect('localhost', 'root', '');
#mysql_select_db('neiasite');
Can you help me please?
Thanks for reading.
In Godaddy, or any other shared hosting, you will not be given root user access to database. You need to create an user and password for your database.
This link will explain how.
https://support.godaddy.com/help/article/36/creating-mysql-or-sql-server-databases-for-your-hosting-account
And you need to use MySQLi to connect
$link = mysqli_connect("localhost","use_your_username","use_your_password","your_database_name") or die("Error " . mysqli_error($link));
Remember to import you existing database to godaddy from your localhost.
And i guess you should take a look at this tutourial on how to connect to godaddy mysql
http://www.prophoto.com/support/godaddy-mysql/
Hola! Thank you so very much for helping me.
I have successfully fixed it with this code:
mysql_connect("localhost", "username", "password")or die("cannot connect to server");
mysql_select_db("db_name")or die("cannot select db");
Source: http://www.phpeasystep.com/mysql/4.html.
Pce. (:
#Arun, #Andre, #Gopakumar Gopalan, #Djip
Am trying to connect with my database using php from my website. I have used following codes to make connection,
$db_host="10.12.209.82";
$db_username="username";
$db_pass="pass";
$db_name="DBName";
mysql_connect($db_host,$db_username,$db_pass) or die("Could not connect to my sql");
mysql_connect($db_name) or die("No Database");
But when i run the file in my website it shows the following error...
Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator to inform of the time the error occurred and of anything you might have done that may have caused the error.
More information about this error may be available in the server error log.
What was the issue and where I made mistake?
don't use mysql its already deprecated use MySQLI or PDO instead..
USING MySQLI you can connect to your server just doing this..
define('HOST','10.12.209.82');
define('USER','username');
define('PASSWORD','password');
define('Database','dbname');
$dbh = mysqli_connect(HOST,USER,PASSWORD,DATABASE) or die('Cannot connect to the server');
Should be (mysql_select_db):
$db_host="localhost";
$db_username="root";
$db_pass="302010asd";
$db_name="mvnodb";
mysql_connect($db_host, $db_username, $db_pass) or die("Could not connect to my sql");
mysql_select_db($db_name) or die("No Database");
Invoking mysql_connect again and not supplying properly parameters raises a error.
I am very new to php, and i am trying to connect to ftp and post a form, which has a few text fields, and 3 image upload, the images will be uploaded to the server. I am using godaddy, and they dont allow ftp_connect, only fsocketopen(),and only available on ports 80 (http) and 443(https). Can i have some advice on how to approach this(fsockopen)?
I researched and below is what i got, i assume the first part is server, second part is the port so i assume is 80(as godaddy said only that 2 ports are available), but what are the last 3? The $error_number,$error_string, and the last part?
Thanks for your time. Sorry that if the question is a newbie question. I researched for a while, i still can't fix it.
fsockopen('abc.com', '80', $error_number, $error_string, 30)
<?php
$ftp_user_name='name';
$ftp_user_pass='pass';
$connection = 'server';
$errno='';
$connect= fsockopen("abc.info", 80, $errno, $errstr, 30) or die ("Cannot connect to host");
$login = ftp_login($connect, $ftp_user_name, $ftp_user_pass);
if (!$connect)
{die ("FTP connection has encountered an error!");}
//exit;
if (!$login)
{die ("But failed at login Attempted to connect to $connection for user $ftp_user_name....");}
?>
At the risk of sounding conceited, RTM please.
From the PHP Docs:
errno If provided, holds the system level error number that
occurred in the system-level connect() call. If the value returned in
errno is 0 and the function returned FALSE, it is an indication that
the error occurred before the connect() call. This is most likely due
to a problem initializing the socket.
errstr The error message as a string.
timeout The connection timeout, in seconds.
We are using the below script.
Actually our DB is in one server (say www.server1.com) and the PHP file
containing the below connection string is in another server (say
www.server2.com)
If we place the PHP file containing the below script in the same server
where the DB exists that is www.server1.com/dbconnection.php it is working
fine.
But if we place the PHP file containing the below script in another server
www.server2.com/dbconnection.php it is not working. This displays the
error 'Something went wrong while connecting to MSSQL' Please advise.
Also to handle error if we use 'die('MSSQL error: ' .
mssql_get_last_message());' nothing displays just an empty page.
Please advise how to handle errors.
Script (dbconnection.php)
$server = 'xxx.xxx.xxx.x,xxxx'; //IP, Port
// Connect to MSSQL
$link = mssql_connect($server, 'username', 'password');
if (!$link) {
die('Something went wrong while connecting to MSSQL');
}
// Connect to DB
$db=mssql_select_db("databasename",$link) or die("Unable to select
database ");
Thank You
How to get error message, I do not know, but if you are migrating your PHP app from windows server to linux (FTP servers are more usual on linux), you can try change:
$server = 'xxx.xxx.xxx.x,xxxx'; //IP, Port
to
$server = 'xxx.xxx.xxx.x:xxxx'; //IP: Port
As described in first parameter of manual: http://www.php.net/manual/en/function.mssql-connect.php