Re: Socket class, connect to an endpoint with port 21
- From: "Ignacio Machin \( .NET/ C# MVP \)" <machin TA laceupsolutions.com>
- Date: Mon, 11 Feb 2008 08:49:53 -0500
Hi,
Do you know by any change if your network has a firewall?
It seems that you might have a FTP proxy server soemwhere in between.
--
Ignacio Machin
http://www.laceupsolutions.com
Mobile & warehouse Solutions.
"Diego Escalona" <sfdgffgd@xxxxxxx> wrote in message
news:OP6m4LLbIHA.2268@xxxxxxxxxxxxxxxxxxxxxxx
Hello everybody,
I'm developing a FTP Client using the socket class. Here is the code I use
to declare the socket:
Socket FTP_Socket = new Socket(AddressFamily.InterNetwork,
SocketType.Stream, ProtocolType.Tcp);
I've developed other applications (not with the port 21) with sockets and
to verify the connection I always use the Socket.Connected var. In this
case I noticed that there was a problem because the FTP_Socket always
connects (gets Connected var true) to the remote Endpoint. It doesn't mind
the IP Address, it always connects if the remote Endpoint uses the port
21. In order to verify that, I've developed a little tool that makes
simple socket connections and I always obtain the same results, it
connects to any IP Address (they can be not real) if I use the port 21.
Here is the code I use to connect with my little tool:
private void connect()
{
try
{
FTP_Socket.Connect(EndP);
}
catch
{
MessageBox.Show("Couldn't connect to the remote host " +
ip.ToString(), "Connection Error", MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
connection_finished();
}
private void connection_finished()
{
if (this.InvokeRequired)
{
ConnFinishCallback d = new ConnFinishCallback(connection_finished);
Invoke(d, new object[] { });
}
else
{
if (FTP_Socket.Connected)
LStatus.Text = "Connected to " + ip.ToString();
else
LStatus.Text = "Disconnected";
}
}
Socket.Connect(EndPoint remoteEP) is a blocking method (I run it in
another Thread), if it can't make the connection it should take about 20
secs trying to connect to the endpoint and if it can make the connection
it did inmediatly. If it doesn't connect, a message is shown, anyway I
call the connection_finished method that checks if FTP_Socket.Connected is
true or false to keep on with the main program. The problem is that as I
use the port 21 for the FTP Client, I always obtain the Socket.Connected
true.
What is the problem with the port 21?
I've solved my problem cheking if I receive any response after the
connection, but I would like to know why the Socket doesn't try to connect
to any endpoint that uses the port 21 and puts the Socket.Connected var
always to true.
Regards,
Diego Escalona.
.
- Follow-Ups:
- Re: Socket class, connect to an endpoint with port 21
- From: Diego Escalona
- Re: Socket class, connect to an endpoint with port 21
- References:
- Socket class, connect to an endpoint with port 21
- From: Diego Escalona
- Socket class, connect to an endpoint with port 21
- Prev by Date: Re: Generic method & constraint
- Next by Date: Re: Generic method & constraint
- Previous by thread: Socket class, connect to an endpoint with port 21
- Next by thread: Re: Socket class, connect to an endpoint with port 21
- Index(es):