/// <summary> Constructs a new <code>FTPDataSocket</code> object (client mode) and connect
        /// to the given remote host and port number.
        /// 
        /// </summary>
        /// <param name="ipAddress">IP Address to connect to.
        /// </param>
        /// <param name="port">Remote port to connect to.
        /// </param>
        /// <returns> A new <code>FTPDataSocket</code> object (client mode) which is
        /// connected to the given server.
        /// </returns>
        /// <throws>  SystemException Thrown if no TCP/IP connection could be made.  </throws>
        internal virtual FTPDataSocket NewPassiveDataSocket(string ipAddress, int port)
        {
            IPAddress ad = IPAddress.Parse(ipAddress);
            IPEndPoint ipe = new IPEndPoint(ad, port);
            BaseSocket sock =
                new StandardSocket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            SetSocketTimeout(sock, timeout);
            sock.Connect(ipe);

            return new FTPPassiveDataSocket(sock);
        }
        /// <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);
        }
Example #3
0
 internal virtual FTPDataSocket NewPassiveDataSocket(string ipAddress, int port)
 {
     this.log.Debug(string.Concat(new object[] { "NewPassiveDataSocket(", ipAddress, ",", port, ")" }));
     IPEndPoint remoteEP = new IPEndPoint(IPAddress.Parse(ipAddress), port);
     BaseSocket sock = new StandardSocket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
     try
     {
         this.SetSocketTimeout(sock, this.timeout);
         sock.Connect(remoteEP);
     }
     catch (Exception exception)
     {
         this.log.Error("Failed to create connecting socket", exception);
         sock.Close();
         throw;
     }
     return new FTPPassiveDataSocket(sock);
 }
Example #4
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);
 }
Example #5
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);
        }
Example #6
0
 /// <summary> Constructs a new <code>FTPDataSocket</code> object (client mode) and connect
 /// to the given remote host and port number.
 /// 
 /// </summary>
 /// <param name="ipAddress">IP Address to connect to.
 /// </param>
 /// <param name="port">Remote port to connect to.
 /// </param>
 /// <returns> A new <code>FTPDataSocket</code> object (client mode) which is
 /// connected to the given server.
 /// </returns>
 /// <throws>  SystemException Thrown if no TCP/IP connection could be made.  </throws>
 internal virtual FTPDataSocket NewPassiveDataSocket(string ipAddress, int port)
 {
     log.Debug("NewPassiveDataSocket(" + ipAddress + "," + port + ")");
     IPAddress ad = IPAddress.Parse(ipAddress);  
     IPEndPoint ipe = new IPEndPoint(ad, port); 
     BaseSocket sock =
         new StandardSocket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp, logTag);
     try
     {
         SetSocketTimeout(sock, timeout);
         sock.Connect(ipe, timeout);
         log.Debug("Connected");
     }
     catch (Exception ex)
     {
         log.Error("Failed to create connecting socket", ex);
         sock.Close();
         throw;
     }
     return new FTPPassiveDataSocket(sock);
 }