Php ftp_connect fails, FTP client connects - php

(this question might not belong here, but on ServerFault, I don't know exactly where the problem comes from)
I'm trying to connect to an FTP server like this:
$con = ftp_connect( '86.xxx.xx.xxx', 21 ) or die("FTP connect error");
and it always throws me the error message.
I can connect like this to other FTP servers, but not this one. I can also connect to this one via an FTP client.
What server settings could be wrong that permit a client connect but not PHP?
Thanks for any help!

It seems my host was blocking remote FTP access to other servers. Oddly enough it allowed me to connect to my other servers at this host.

Related

Error 500 ( Fatal Error ) using pg_connect() in php

im trying to use pg_connect to access postgres on another server,,
i did opened the remote access and i can use bash to connect to my postgres server ! and i did host all all client_ip/32 trust in config but when im trying to use pg_connect i get error 500 !
pgsql is also installed and i've checked it with function_exists('pg_connect') and i returns true !
my code is :
$dbconn = pg_connect("host=remote_IP port=5432 dbname=myDB user=postgres") or die("Could not connect");
i've also tried this and get fatal error 500 again
$dbconn = pg_connect("host=remote_IP port=5432 dbname=myDB
user=another_super_user_i_made password=user_password") or die("Could not connect");
what is the problem ?
when you are able to connect to a server from one machine on your network, but get a connection timed out issue from another machine, it usually is due to one of a few things.
1) DNS. The machine you are testing from (the "remote access" as you call it) is able to resolve the DNS name and the webserver running your PHP code is not. You can use actual IP address instead of DNS names to test this.
2) Connectivity. Different machines are connected in different ways in a network. If you are able to get to an IP from the "remote access" machine but the web server is having trouble connecting to it (with "connection timed out"), try connecting directly to that web server (using "remote access" like SSH) and see if you can connect manually from there.
If it's not a network related issue it could be an issue with your default PG timeouts. Try setting them manually with the connect string. Specifically, the "connect_timeout" option, like this:
$d=pg_connect('host=example.com user=pgsql dbname=postgres connect_timeout=5');
There was host blocking issue !
my client hosting was not enabling remote access to DB !
you should check with your hosting that they can trace your problem

Cannot connect to server from another server ftp php

I work with 2 servers one is my production server other is my resource server.
I cannot connect to my resource server from my production server over ftp.
I can connect to other servers from my production server.
I can also connect to my resource server from my localhost or filezilla.
I use this code to connect :
$conn_id = ftp_connect("resource server ip", "21", "5");
if ($conn_id) {
echo "connected";
ftp_close($conn_id);
}
print_r(error_get_last());
I don't get any output when I run this script on server(no error).
On localhost it runs no problem.
What can be the problem with this? Is this something that server admin has to resolve? Thanks for help.
You should first check from commandline, whether it's a networking/OS issue or not.
So if you've got shell access to the production server try connecting to the resource server via the commandline ftp client.
If that does not work, you've got a network / firewall / access control problem, not related to php or your software, and you should talk to the sysadmin.
If it does work, then the problem is in your stuff, and you should set the log levels to high, and run this script from commandline, also check the logs of php, php-error, syslog and the resource servers ftp access log and syslog too.
Note: ftp is a not-too-exact beast, the servers and clients have a lot of workarounds built in to treat each other in a way, that works somehow. There could be issues from active (multiple back-and-forth connections) and passive mode (it's like http), also with ls formats and timestamps, timezones and ports.
Also some servers only support ftps (ftp with ssl) - which is not the same as sftp (file transfer over ssh - port 22).
Your production server probably has some firewall rules, and your connection get caught on that, to debug this, please use the commandline ftp client, and/or nmap / netcat.

Can't connect to remote SQL database in PHP, but remote access is set up and confirmed working

I'm trying to learn to use SQL stuff in PHP but I'm having an issue simply connecting to my database.
The database is almost certainly working with remote access to some extent. I disabled iptables temporarily (I know, bad bad bad!), so there's no firewall blocking access. The MySQL user I am using is configured to be able to connect from any IP. The SQL server is listening properly to all connections and is run on a Linux dedicated server.
[root#1742CC-XEON ~]# netstat -lpnut | grep mysql
tcp 0 0 0.0.0.0:3315 0.0.0.0:* LISTEN 3915/mysqld
I've also used the exact same credentials to successfully remotely connect to my database in Java, like so:
Class.forName("com.mysql.jdbc.Driver");
Connection conn = DriverManager.getConnection("jdbc:mysql://__ip__:_port_/_dbname_", "username", "password");
System.out.println("Connection established.");
This functions just fine, and I can successfully run queries, etc. Since I have iptables disabled at the moment this connection functions just fine anywhere that has Java and the Java SQL connector.
Now, I'm trying to connect to the same database in PHP:
$db = mysqli_connect($sql_host, $sql_user, $sql_pass, $sql_db, $sql_port);
And this connection fails with the following error:
Warning: mysqli_connect(): (HY000/2003): Can't connect to MySQL server on 'xx.xx.xx.ip' (111)
Note that $sql_user, $sql_pass, $sql_host, etc. are all the same as the credentials used in the Java connection, so there shouldn't be any issue with the user not being able to access the server from a new IP, since that user is granted access on % and I've made sure that it is indeed able to access the SQL server from multiple IPs not explicitly allowed in the users table. I've also tried different users, including root, and all give the same connection error.
I've spent a few hours looking around but I honestly can't find anything that seems to be the right answer, would really appreciate any help!
Is it possible that this is caused by my webhost? I've tried this script on HostGator webhost as well as the whois.com hosting and both give the same error. Could they possibly be preventing the PHP script from connecting to the remote database?
Have you tried telneting to the server on 3315 from your webhosts?

SFTP not connecting to remote server

I am trying to connect to a remote SFTP server using PHP. My code works fine when I connect to a local SFTP account but it times out for remote host. I have made sure through FTP client that host information is correct and its connecting fine.
I am using phpseclib library and my three line code is below.
require_once("phpseclib/Net/SFTP.php");
$sftp = new Net_SFTP('remote_host_IP');
var_dump($sftp->login('<username>', '<password>'));
It returns false (meaning not connected).
What I have done
I have whitelisted script in mod_security just in case its blocking that.
I have tried same script on my local computer and it connects successfully to remote SFTP.
Any valuable hint please?
Do define('NET_SSH2_LOGGING', 2) before initializing Net_SFTP and then do $sftp->getLog() after $sftp->login()
That'll provide enough info with which a diagnostic can be made.
This might help others. You need to make sure TCP_OUT port is open on your remote server to make it work.
Thanks for the help!

Why won't my server connect to a remote MSSQL server using PHP mssql_connect?

I've had to move an app we wrote for a client to a new server and a remote connection I was initiating with PHP mssql_connect has ceased to work. I noticed that PHP wasn't compiled with mssql so I asked the server admin to install it. I can verify that it's now installed via PHP info but I now get a consistent "Unable to connect to server" error from mssql_connect.
Here's the very simple PHP script I'm running:
$myServer = "myserver.com:5000";
$myUser = "myusername";
$myPass = "mypassword";
$dbhandle = mssql_connect($myServer, $myUser, $myPass)
or die("Couldn't connect to SQL Server on $myServer. Error: " . mssql_get_last_message());
I've confirmed that the credentials are still correct but for whatever reason it seems that mssql_connect just isn't doing it's thing. I'm wondering if there's something that the admin has forgotton to do having installed the extension and FreeTDS. Any pointers greatly appreciated! :)
PROBLEM SOLVED!!!
After all that it turned out to be the FreeTDS protocol version number as specified in /usr/local/freetds/etc/freetds.conf, line number 13 had to be uncommented. That was it! :)
After all that it turned out to be the FreeTDS protocol version number as specified in /usr/local/freetds/etc/freetds.conf, line number 13 had to be uncommented. That was it! :)
There's a good chance that remote connections are disabled on the server where the server is installed. Have you checked whether you are actually able to connect to the DB server remotely, from the IP address of the webserver that attempts to connect to it? Usually, at least in most shared hosting schemes, the database server only accepts connections from localhost. You'd need to add the IP address of the webserver to a whitelist (usually in the server's configuration) to allow connections from the outside.

Categories