Beispiel #1
0
 private void CloseDataConn()
 {
     if (dataConn != null)
     {
         //如果当前的dataConn还在处于等待连接或者发送数据状态,就取消这些操作
         dataConn.AsyncHelper.CancelAsyncOperation();
         dataConn.Stop();
         dataConn = null;
     }
 }
Beispiel #2
0
        void CreateDataConnection()
        {
            //关闭以前的数据连接
            CloseDataConn();

            //生成新的数据连接
            dataConn = new FtpDataConnection();
            dataConn.Start();

            IPEndPoint    localPoint = (IPEndPoint)dataConn.Socket.LocalEndPoint;
            string        ipAddress  = ftpServer.PasvIPSetting.Replace(".", ",");
            StringBuilder reply      = new StringBuilder();

            reply.Append("227 Entering Passive Mode(");
            reply.Append(ipAddress);
            reply.Append(",");
            reply.Append(localPoint.Port / 256);
            reply.Append(",");
            reply.Append(localPoint.Port % 256);
            reply.Append(").");

            Response(reply.ToString());

            try
            {
                //在规定时间内等待客户端的数据连接
                dataConn.Accept(opertionTimeout);
            }
            catch (TimeoutException)
            {
                CloseDataConn();
                NetDebuger.PrintDebugMessage("Timeout  wait for data connection");
            }
            catch
            {
                CloseDataConn();
                NetDebuger.PrintDebugMessage("Interrupted for wait for data connection");
            }
        }