Jump to content

Possible To Have A Script Forward Port 80 To Port 21 To Handle Incoming Ftp Requests?


Rheves

Recommended Posts

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!

Link to comment
Share on other sites

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
}

Link to comment
Share on other sites

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.

 

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.