Rheves Posted November 13, 2012 Share Posted November 13, 2012 I have an FTP server set up in our office, and would like to be able to connect to it all the time (At the office, and at home) using a no-ip.org domain I set up to point to it's external IP. Works great outside the office, but we need to use the internal IP whenever we are in the office as expected. What I wanted to do was set up a php script as index.php on the wamp server I just threw on there which looks like this: <?php $LocalIP = $_SERVER['SERVER_ADDR']; $IncomingIP = $_SERVER['REMOTE_ADDR']; if ($LocalIP == $IncomingIP){ header('Location: 192.168.2.200'); }else{ header('Location: ***.no-ip.org:21'); } ?> It...doesn't work. I'm trying to connect using the no-ip domain and port 80 in my ftp client. Is this flawed from the start or would I be able to get this working? Locally I get this error: Status: Connecting to ****:80...Status: Connection established, waiting for welcome message... Response: HTTP/1.1 400 Bad Request Error: Could not connect to server And outside the office I get this: Status: Connecting to ****:80...Status: Connection established, waiting for welcome message... Error: Connection timed out Error: Could not connect to server Any help in getting this working or letting me know if it's impossible would be appreciated! Quote Link to comment https://forums.phpfreaks.com/topic/270621-possible-to-have-a-script-forward-port-80-to-port-21-to-handle-incoming-ftp-requests/ Share on other sites More sharing options...
gizmola Posted November 13, 2012 Share Posted November 13, 2012 The remote_addr is not going to = the server's address. What you really want is to do is just compare the network portion of the numbers. There's a few different ways to do this, but here's one that mimics the way netmasks work. Yours needs to match whatever subnet your workstations actually use... I'm assuming it's a class C standard here, and also assuming your internal network is 192.168.2. $netmask = ip2long('255.255.255.0'); $internal = ip2long('192.168.2.0'); $remote = ip2long($_SERVER['REMOTE_ADDR']) & $netmask; if ($internal == $remote) { // Intranet client } else { // External client } Quote Link to comment https://forums.phpfreaks.com/topic/270621-possible-to-have-a-script-forward-port-80-to-port-21-to-handle-incoming-ftp-requests/#findComment-1391980 Share on other sites More sharing options...
gizmola Posted November 13, 2012 Share Posted November 13, 2012 Aside from the IP checks, I realized there are additional hurdles. I don't really have enough information in regards to what you're trying to do. FTP servers do not implement the HTTP protocol. Many browsers however, will work with ftp:// as a scheme. What this means is that they'll pass ftp commands back and forth to a server because they have scheme handling functions that facilitate this. Conversely, ftp clients aren't web browsers. All they know how to do is talk to web servers. An ftp client doesn't understand HTTP protocol, so a php script that does HTTP Location header redirects isn't going to work for an ftp client. Quote Link to comment https://forums.phpfreaks.com/topic/270621-possible-to-have-a-script-forward-port-80-to-port-21-to-handle-incoming-ftp-requests/#findComment-1391983 Share on other sites More sharing options...
Rheves Posted November 13, 2012 Author Share Posted November 13, 2012 I worried that might be the case, thanks for the info. Quote Link to comment https://forums.phpfreaks.com/topic/270621-possible-to-have-a-script-forward-port-80-to-port-21-to-handle-incoming-ftp-requests/#findComment-1391987 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.