internal virtual void AcceptConnection()
 {
     if (this.acceptedSock == null)
     {
         this.acceptedSock = base.sock.Accept(base.timeout);
         base.SetSocketTimeout(this.acceptedSock, base.timeout);
         this.log.Debug("AcceptConnection() succeeded");
     }
 }
 internal override void Close()
 {
     try
     {
         if (this.acceptedSock != null)
         {
             this.acceptedSock.Close();
             this.acceptedSock = null;
         }
     }
     finally
     {
         base.sock.Close();
     }
 }
Example #3
0
 internal void SetSocketTimeout(BaseSocket sock, int timeout)
 {
     if (timeout > 0)
     {
         try
         {
             sock.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReceiveTimeout, timeout);
             sock.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.SendTimeout, timeout);
         }
         catch (SocketException exception)
         {
             this.log.Warn("Failed to set socket timeout: " + exception.Message);
         }
     }
 }
Example #4
0
 internal FTPControlSocket()
 {
     this.log = Logger.GetLogger("FTPControlSocket");
     this.synchronizePassiveConnections = false;
     this.strictReturnCodes = false;
     this.remoteHost = null;
     this.remoteAddr = null;
     this.controlPort = -1;
     this.controlSock = null;
     this.timeout = 0;
     this.writer = null;
     this.reader = null;
     this.activePortRange = null;
     this.activeIPAddress = null;
     this.nextPort = 0;
     this.autoPassiveIPSubstitution = false;
 }
Example #5
0
 internal FTPControlSocket(string remoteHost, int controlPort, int timeout, Encoding encoding)
 {
     this.log = Logger.GetLogger("FTPControlSocket");
     this.synchronizePassiveConnections = false;
     this.strictReturnCodes = false;
     this.remoteHost = null;
     this.remoteAddr = null;
     this.controlPort = -1;
     this.controlSock = null;
     this.timeout = 0;
     this.writer = null;
     this.reader = null;
     this.activePortRange = null;
     this.activeIPAddress = null;
     this.nextPort = 0;
     this.autoPassiveIPSubstitution = false;
     if (this.activePortRange != null)
     {
         this.activePortRange.ValidateRange();
     }
     this.Initialize(new StandardSocket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp), remoteHost, controlPort, timeout, encoding);
 }
 /// <summary>
 /// Closes underlying sockets
 /// </summary>
 internal override void Close()
 {
     if (acceptedSock != null)
     {
         acceptedSock.Close();
         acceptedSock = null;
     }
     sock.Close();
 }
 /// <summary>  
 /// Constructor
 /// </summary>
 /// <param name="sock">   the server socket to use
 /// </param>
 internal FTPActiveDataSocket(BaseSocket sock)
 {
     this.sock = sock;
 }
Example #8
0
		/// <summary>
		/// Closes underlying sockets
		/// </summary>
		internal override void Close()
		{
            try
            {
                if (acceptedSock != null)
                {
                    acceptedSock.Close();
                    acceptedSock = null;
                }
            }
            finally
            {
                sock.Close();
            }
		}
 /// <summary> 
 /// Waits for a connection from the server and then sets the timeout
 /// when the connection is made.
 /// </summary>
 internal virtual void AcceptConnection()
 {
     if (acceptedSock == null)
     {
         acceptedSock = sock.Accept();
         SetSocketTimeout(acceptedSock, timeout);
     }
 }
Example #10
0
		/// <summary>  
		/// Constructor
		/// </summary>
		/// <param name="sock">   the server socket to use
		/// </param>
		internal FTPActiveDataSocket(BaseSocket sock)
		{
			this.sock = sock;
            log = Logger.GetLogger("FTPActiveDataSocket");
		}
Example #11
0
		/// <summary> 
		/// Waits for a connection from the server and then sets the timeout
		/// when the connection is made.
		/// </summary>
		internal virtual void AcceptConnection()
		{
			if (acceptedSock == null)
			{
				acceptedSock = sock.Accept(timeout);		
    			SetSocketTimeout(acceptedSock, timeout);
                log.Debug("AcceptConnection() succeeded");
			}
		}
 /// <summary>  
 /// Helper method to set a socket's timeout value
 /// </summary>
 /// <param name="sock">
 /// socket to set timeout for
 /// </param>
 /// <param name="timeout">
 /// timeout value to set
 /// </param>
 internal void SetSocketTimeout(BaseSocket sock, int timeout)
 {
     if (timeout > 0)
     {
         sock.SetSocketOption(SocketOptionLevel.Socket,
             SocketOptionName.ReceiveTimeout, timeout);
         sock.SetSocketOption(SocketOptionLevel.Socket,
             SocketOptionName.SendTimeout, timeout);
     }
 }
Example #13
0
 internal void Kill()
 {
     try
     {
         if (controlSock != null)
             controlSock.Close();
         controlSock = null;
     }
     catch (Exception e)
     {
         log.Debug("Killed socket", e);
     }
     log.Info("Killed control socket");
 }
 /// <summary>   
 /// Establishes the socket connection
 /// </summary>
 /// <param name="socket">
 ///  Socket instance
 /// </param>
 /// <param name="address">     
 /// IP address to connect to
 /// </param>
 /// <param name="port">    
 /// port to connect to     
 /// </param>
 internal virtual void ConnectSocket(BaseSocket socket, IPAddress address, int port)
 {
     socket.Connect(new IPEndPoint(address, port));
 }
Example #15
0
 internal virtual void Logout()
 {
     SystemException t = null;
     try
     {
         this.writer.Close();
     }
     catch (SystemException exception2)
     {
         t = exception2;
     }
     try
     {
         this.reader.Close();
     }
     catch (SystemException exception3)
     {
         t = exception3;
     }
     try
     {
         this.controlSock.Close();
         this.controlSock = null;
     }
     catch (SystemException exception4)
     {
         t = exception4;
     }
     if (t != null)
     {
         this.log.Error("Caught exception", t);
         throw t;
     }
 }
Example #16
0
 internal void Kill()
 {
     try
     {
         if (this.controlSock != null)
         {
             this.controlSock.Close();
         }
         this.controlSock = null;
     }
     catch (Exception exception)
     {
         this.log.Debug("Killed socket", exception);
     }
     this.log.Info("Killed control socket");
 }
Example #17
0
 internal void Initialize(BaseSocket sock, string remoteHost, int controlPort, int timeout, Encoding encoding)
 {
     this.remoteHost = remoteHost;
     this.controlPort = controlPort;
     this.timeout = timeout;
     this.controlSock = sock;
     this.ConnectSocket(this.controlSock, remoteHost, controlPort);
     this.Timeout = timeout;
     this.InitStreams(encoding);
 }
Example #18
0
 /// <summary>  
 /// Quit this FTP session and clean up.
 /// </summary>
 internal virtual void Logout()
 {
     
     SystemException ex = null;
     try
     {
         writer.Close();
     }
     catch (SystemException e)
     {
         ex = e;
     }
     try
     {
         reader.Close();
     }
     catch (SystemException e)
     {
         ex = e;
     }
     try
     {
         controlSock.Close();
         controlSock = null;
     }
     catch (SystemException e)
     {
         ex = e;
     }
     if (ex != null) 
     {
         log.Error("Caught exception", ex);
         throw ex;
     }
 }
        /// <summary>   
        /// Performs TCP connection and sets up reader/writer. 
        /// Allows different control port to be used
        /// </summary>
        /// <param name="sock">
        ///  Socket instance
        /// </param>
        /// <param name="remoteHost">     
        /// address of remote host
        /// </param>
        /// <param name="controlPort">     
        /// port for control stream
        /// </param>
        /// <param name="timeout">    
        /// the length of the timeout, in milliseconds      
        /// </param>
        internal void Initialize(BaseSocket sock, IPAddress remoteHost, int controlPort, int timeout)
        {
            this.remoteHost = remoteHost;
            this.controlPort = controlPort;
            this.timeout = timeout;

            log = Logger.GetLogger(typeof(FTPControlSocket));

            // establish socket connection & set timeouts
            controlSock = sock;
            ConnectSocket(controlSock, remoteHost, controlPort);
            Timeout = timeout;

            InitStreams();
            ValidateConnection();
        }
Example #20
0
 internal virtual void ConnectSocket(BaseSocket socket, string address, int port)
 {
     this.remoteAddr = HostNameResolver.GetAddress(address);
     socket.Connect(new IPEndPoint(this.remoteAddr, port));
 }
 internal FTPPassiveDataSocket(BaseSocket sock)
 {
     base.sock = sock;
 }
Example #22
0
        /// <summary>   
        /// Performs TCP connection and sets up reader/writer. 
        /// Allows different control port to be used
        /// </summary>
        /// <param name="sock">
        ///  Socket instance
        /// </param>
        /// <param name="remoteHost">     
        /// address of remote host
        /// </param>
        /// <param name="controlPort">     
        /// port for control stream
        /// </param>
        /// <param name="timeout">    
        /// the length of the timeout, in milliseconds      
        /// </param>
        /// <param name="encoding">          
        /// encoding to use for control channel
        /// </param>
        internal void Initialize(BaseSocket sock, string remoteHost, int controlPort, 
			int timeout, Encoding encoding)
        {
            this.remoteHost = remoteHost;
            this.controlPort = controlPort;
            this.timeout = timeout;
            
            // establish socket connection & set timeouts
            controlSock = sock;
            ConnectSocket(controlSock, remoteHost, controlPort);
            Timeout = timeout;
            
            InitStreams(encoding);
        }