Esempio n. 1
0
        public virtual void Close()
        {
            StopListener();

            if (Client != null && !m_IsClosed)
            {
                try
                {
                    Client.Shutdown(SocketShutdown.Both);
                }
                catch (Exception e)
                {
                    m_Session.Logger.Error(e);
                }

                try
                {
                    Client.Close();
                }
                catch (Exception e)
                {
                    m_Session.Logger.Error(e);
                }
                finally
                {
                    Client     = null;
                    m_Session  = null;
                    m_IsClosed = true;
                    OnClose();
                }
            }
        }
Esempio n. 2
0
        internal static bool TryOpenDataConnection(FtpSession session, out DataConnection dataConnection)
        {
            dataConnection = null;

            int tryPort      = session.AppServer.FtpServiceProvider.GetRandomPort();
            int previousPort = tryPort;
            int tryTimes     = 0;

            IPAddress ipAddress = session.LocalEndPoint.Address;

            while (true)
            {
                var listenSocket = TryListenSocketPort(ipAddress, tryPort);

                if (listenSocket != null)
                {
                    dataConnection = new DataConnection(session, listenSocket, tryPort);
                    return(true);
                }

                tryTimes++;

                if (tryTimes > 5)
                {
                    return(false);
                }

                tryPort = session.AppServer.FtpServiceProvider.GetRandomPort();

                if (previousPort == tryPort)
                {
                    return(false);
                }
            }
        }
Esempio n. 3
0
        internal static bool TryOpenDataConnection(FtpSession session, int port, out DataConnection dataConnection)
        {
            // Issues the Active mode is connect, and not listen??
            IPAddress ipAddress = session.RemoteEndPoint.Address;

            dataConnection = new DataConnection(session, ipAddress, port);
            return(true);
        }
Esempio n. 4
0
 public DataConnection(FtpSession session, Socket listenSocket, int port)
 {
     m_Session      = session;
     m_Address      = session.Config.Ip;
     SecureProtocol = session.Context.DataSecureProtocol;
     m_Listener     = listenSocket;
     m_Port         = port;
 }
Esempio n. 5
0
 public DataConnection(FtpSession session, IPAddress address, int port)
 {
     m_Session           = session;
     Address             = session.Config.Ip;
     SecureProtocol      = session.Context.DataSecureProtocol;
     m_Listener          = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.IP);
     m_ipAddress         = address;
     Port                = port;
     _dataConnectionType = DataConnectionType.Active;
 }
Esempio n. 6
0
        internal static bool TryOpenDataConnection(FtpSession session, int port, out DataConnection dataConnection)
        {
            IPAddress ipAddress    = session.LocalEndPoint.Address;
            var       listenSocket = TryListenSocketPort(ipAddress, port);

            if (listenSocket != null)
            {
                dataConnection = new DataConnection(session, listenSocket, port);
                return(true);
            }

            dataConnection = null;
            return(false);
        }