FTP PORT实现遇到一个问题 请高手指点 内附代码
我实现PORT的代码,代码主要是获取一个Data Stream ,大概如下:
string localHostName = System.Net.Dns.GetHostName();
System.Net.IPHostEntry ipHost = System.Net.Dns.GetHostByName(localHostName);
IPAddress ipHostAddress = ipHost.AddressList[0];
Socket activeSocket = null;
TcpListener listener = new TcpListener(ipHostAddress,0);//这里会自动获得一个监听端口
//开始监听本地端口,等待FTP服务器连接
listener.Start();
IPEndPoint endPoint =(IPEndPoint)listener.LocalEndpoint;
//发送PORT命令
this.SendCommand(endPoint);
if(m_lastResponse.Code == FtpResponse.EnterActiveMode)//如果replay 返回的是 200
{
if(activeSocket == null)
activeSocket = listener.AcceptSocket();
//问题:这句是在这里写吗?调试的时候 运行到这里系统会等待很久。不知道为什么
//...
return new NetworkStream(activeSocket,true);
}