Exemplo n.º 1
0
 internal virtual FTPDataSocket NewActiveDataSocket(int port)
 {
     BaseSocket sock = new StandardSocket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
     try
     {
         this.log.Debug("NewActiveDataSocket(" + port + ")");
         IPEndPoint localEP = new IPEndPoint(((IPEndPoint) this.controlSock.LocalEndPoint).Address, port);
         sock.Bind(localEP);
         sock.Listen(5);
         this.SetDataPort((IPEndPoint) sock.LocalEndPoint);
     }
     catch (Exception exception)
     {
         this.log.Error("Failed to create listening socket", exception);
         sock.Close();
         throw;
     }
     return new FTPActiveDataSocket(sock);
 }
Exemplo n.º 2
0
        /// <summary> 
        /// Constructs a new <code>FTPDataSocket</code> object (server mode) which will
        /// listen on the given port number.
        /// </summary>
        /// <param name="port">Remote port to listen on.
        /// </param>
        /// <returns> A new <code>FTPDataSocket</code> object (server mode) which is
        /// configured to listen on the given port.
        /// </returns>
        /// <throws>  SystemException Thrown if an error occurred when creating the socket.  </throws>
        internal virtual FTPDataSocket NewActiveDataSocket(int port)
        {
            // create listening socket at a system allocated port
            BaseSocket sock =
                new StandardSocket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

            // choose any port
            IPEndPoint endPoint = new IPEndPoint(((IPEndPoint)controlSock.LocalEndPoint).Address, 0);
            sock.Bind(endPoint);

            // queue up to 5 connections
            sock.Listen(5);

            // find out ip & port we are listening on
            SetDataPort((IPEndPoint)sock.LocalEndPoint);

            return new FTPActiveDataSocket(sock);
        }
Exemplo n.º 3
0
        /// <summary> 
        /// Constructs a new <code>FTPDataSocket</code> object (server mode) which will
        /// listen on the given port number.
        /// </summary>
        /// <param name="port">Remote port to listen on.
        /// </param>
        /// <returns> A new <code>FTPDataSocket</code> object (server mode) which is
        /// configured to listen on the given port.
        /// </returns>
        /// <throws>  SystemException Thrown if an error occurred when creating the socket.  </throws>
        internal virtual FTPDataSocket NewActiveDataSocket(int port)
        {                        
            // create listening socket at a system allocated port
            BaseSocket sock = 
                new StandardSocket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp, logTag);

            try
            {
                log.Debug("NewActiveDataSocket(" + port + ")");
                
                // choose specified port and listen on all interfaces
                IPEndPoint endPoint = new IPEndPoint(IPAddress.Any, port);
                sock.Bind(endPoint);     

                // queue up to 5 connections
                sock.Listen(5);
                
                // send the *control socket IP* to the server with the listening socket's port
                endPoint = new IPEndPoint(((IPEndPoint)controlSock.LocalEndPoint).Address, ((IPEndPoint)sock.LocalEndPoint).Port);
                SetDataPort(endPoint);
            }
            catch (Exception ex)
            {
                log.Error("Failed to create listening socket", ex);
                sock.Close();
                throw;
            }

            return new FTPActiveDataSocket(sock);
        }