简体   繁体   中英

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM