J
Jim Davis
I am trying to implement a Active mode connection to an FTP server, but
cannot get the server to connect to the port specified by the PORT command.
Below is the code that creates an active data connection. It is based on
code found in the FtpWebRequest class referenced in the following article:
http://aspalliance.com/articleViewer.aspx?aId=253&pId=. When this code
executes, the ftp server never makes a connection to my Socket.
I have seen a couple other examples that look similar. I know Active mode
works with my test FTP server, as I can use a 3rd party product in that mode
without any problems. No doubt there is some simple aspect I am not doing
that I should be. Can someone point out what I am missing.?
Thanks,
Jim
private Socket createDataSocketActive()
{
dataSocket = new Socket( AddressFamily.InterNetwork,
SocketType.Stream, ProtocolType.Tcp );
dataSocket.Blocking = false;
IPHostEntry lhi = Dns.GetHostByName(Dns.GetHostName());
IPEndPoint epListener = new IPEndPoint(lhi.AddressList[0], 0);
dataSocket.Bind(epListener);
dataSocket.Listen(5); // Put the dataSocket * & in Listen mode
//Extract the port of the new Socket to use in the FTP PORT command
IPEndPoint localEP = (IPEndPoint) dataSocket.LocalEndPoint;
Byte[] adrBytes =localEP.Address.GetAddressBytes();
//Format PORT command arguments, Ex: 192,168,0,59,106,223
String szLocal = FormatAddress(adrBytes, localEP.Port);
this.sendCommand("PORT " + szLocal);
if ( this.resultCode != 200 ) throw new
FtpException(this.result.Substring(4));
Socket s = dataSocket.Accept();
return s;
}
cannot get the server to connect to the port specified by the PORT command.
Below is the code that creates an active data connection. It is based on
code found in the FtpWebRequest class referenced in the following article:
http://aspalliance.com/articleViewer.aspx?aId=253&pId=. When this code
executes, the ftp server never makes a connection to my Socket.
I have seen a couple other examples that look similar. I know Active mode
works with my test FTP server, as I can use a 3rd party product in that mode
without any problems. No doubt there is some simple aspect I am not doing
that I should be. Can someone point out what I am missing.?
Thanks,
Jim
private Socket createDataSocketActive()
{
dataSocket = new Socket( AddressFamily.InterNetwork,
SocketType.Stream, ProtocolType.Tcp );
dataSocket.Blocking = false;
IPHostEntry lhi = Dns.GetHostByName(Dns.GetHostName());
IPEndPoint epListener = new IPEndPoint(lhi.AddressList[0], 0);
dataSocket.Bind(epListener);
dataSocket.Listen(5); // Put the dataSocket * & in Listen mode
//Extract the port of the new Socket to use in the FTP PORT command
IPEndPoint localEP = (IPEndPoint) dataSocket.LocalEndPoint;
Byte[] adrBytes =localEP.Address.GetAddressBytes();
//Format PORT command arguments, Ex: 192,168,0,59,106,223
String szLocal = FormatAddress(adrBytes, localEP.Port);
this.sendCommand("PORT " + szLocal);
if ( this.resultCode != 200 ) throw new
FtpException(this.result.Substring(4));
Socket s = dataSocket.Accept();
return s;
}