예제 #1
0
파일: Util.cs 프로젝트: vivarius/ssissftp
        internal static SharpSsh.java.net.Socket createSocket(String host, int port, int timeout)
        {
            SharpSsh.java.net.Socket socket = null;
            String message = "";

            if (timeout == 0)
            {
                try
                {
                    socket = new SharpSsh.java.net.Socket(host, port);
                    return(socket);
                }
                catch (Exception e)
                {
                    message = e.ToString();
                    throw new JSchException(message);
                }
            }
            String _host = host;
            int    _port = port;

            SharpSsh.java.net.Socket[] sockp = new SharpSsh.java.net.Socket[1];
            Thread currentThread             = Thread.CurrentThread;

            Exception[] ee = new Exception[1];
            message = "";
            createSocketRun runnable = new createSocketRun(sockp, ee, _host, _port);
            Thread          tmp      = new Thread(new ThreadStart(runnable.run))
            {
                Name = "Opening Socket " + host
            };

            tmp.Start();
            try
            {
                tmp.Join(timeout);
                message = "timeout: ";
            }
            catch (ThreadInterruptedException eee)
            {
            }
            if (sockp[0] != null && sockp[0].isConnected())
            {
                socket = sockp[0];
            }
            else
            {
                message += "socket is not established. Please check your username, password or port";
                //if (ee[0] != null)
                //{
                //    message = ee[0].ToString();
                //}
                tmp.Interrupt();
                tmp = null;
                throw new JSchException(message);
            }
            return(socket);
        }
예제 #2
0
        internal static Socket createSocket(String host, int port, int timeout)
        {
            Socket socket  = null;
            String message = "";

            if (timeout == 0)
            {
                try
                {
                    socket = new Socket(host, port);
                    return(socket);
                }
                catch (Exception e)
                {
                    message = e.ToString();
                    throw new JSchException(message);
                }
            }
            String _host         = host;
            int    _port         = port;
            var    sockp         = new Socket[1];
            Thread currentThread = Thread.CurrentThread;
            var    ee            = new Exception[1];

            message = "";
            var runnable = new createSocketRun(sockp, ee, _host, _port);
            var tmp      = new Thread(runnable.run);

            tmp.Name = "Opening Socket " + host;
            tmp.Start();
            try
            {
                tmp.Join(timeout);
                message = "timeout: ";
            }
            catch (ThreadInterruptedException)
            {
            }
            if (sockp[0] != null && sockp[0].isConnected())
            {
                socket = sockp[0];
            }
            else
            {
                message += "socket is not established";
                if (ee[0] != null)
                {
                    message = ee[0].ToString();
                }
                tmp.Interrupt();
                tmp = null;
                throw new JSchException(message);
            }
            return(socket);
        }
예제 #3
0
파일: Util.cs 프로젝트: akrisiun/SharpSSH
        internal static Socket createSocket(String host, int port, int timeout)
        {
            Socket socket = null;
            String message = "";
            if (timeout == 0)
            {
                try
                {
                    socket = new Socket(host, port);
                    return socket;
                }
                catch (Exception e)
                {
                    message = e.ToString();
                    throw new JSchException(message);
                }
            }
            String _host = host;
            int _port = port;
            Socket[] sockp = new Socket[1];
            Thread currentThread = Thread.CurrentThread;
            Exception[] ee = new Exception[1];
            message = "";
            createSocketRun runnable = new createSocketRun(sockp, ee, _host, _port);
            Thread tmp = new Thread(new ThreadStart(runnable.run));
            tmp.Name = "Opening Socket " + host;
            tmp.Start();
            try
            {
                tmp.Join(timeout);
                message = "timeout: ";
            }
            catch (ThreadInterruptedException) { }

            if (sockp[0] != null && sockp[0].isConnected())
            {
                socket = sockp[0];
            }
            else
            {
                message += "socket is not established";
                if (ee[0] != null)
                {
                    message = ee[0].ToString();
                }
                tmp.Interrupt();
                tmp = null;
                throw new JSchException(message);
            }
            return socket;
        }
예제 #4
0
 internal static Socket createSocket(String host, int port, int timeout)
 {
     Socket socket = null;
     String message="";
     if(timeout==0)
     {
         try
         {
             /*
             IPEndPoint ep = new IPEndPoint(Dns.GetHostByName(host).AddressList[0], port);
             this.sock = new Sock(ep.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
             //this.sock.Connect(ep);
             this.sock.Connect(ep);
             */
             socket = new Socket(
                 new IPEndPoint(Dns.GetHostEntry(host).AddressList[0], port).AddressFamily,
                 SocketType.Stream,
                 ProtocolType.Tcp
             );
             socket.Connect(host, port);
             return socket;
         }
         catch(Exception e)
         {
             message=e.ToString();
             throw new JSchException(message);
         }
     }
     String _host=host;
     int _port=port;
     Socket[] sockp = new Socket[1];
     Thread currentThread=Thread.CurrentThread;
     Exception[] ee=new Exception[1];
     message="";
     createSocketRun runnable = new createSocketRun(sockp, ee, _host, _port);
     Thread tmp=new Thread(new ThreadStart(runnable.run));
     tmp.Name = "Opening Socket "+host;
     tmp.Start();
     try
     {
         tmp.Join(timeout);
         message="timeout: ";
     }
     catch(ThreadInterruptedException)
     {
     }
     if(sockp[0]!=null && sockp[0].Connected)
     {
         socket=sockp[0];
     }
     else
     {
         message+="socket is not established";
         if(ee[0]!=null)
         {
             message=ee[0].ToString();
         }
         tmp.Interrupt();
         tmp=null;
         throw new JSchException(message);
     }
     return socket;
 }
예제 #5
0
        internal static Socket createSocket(String host, int port, int timeout)
        {
            Socket socket  = null;
            String message = "";

            if (timeout == 0)
            {
                try
                {
                    /*
                     * IPEndPoint ep = new IPEndPoint(Dns.GetHostByName(host).AddressList[0], port);
                     * this.sock = new Sock(ep.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
                     * //this.sock.Connect(ep);
                     * this.sock.Connect(ep);
                     */
                    socket = new Socket(
                        new IPEndPoint(Dns.GetHostEntry(host).AddressList[0], port).AddressFamily,
                        SocketType.Stream,
                        ProtocolType.Tcp
                        );
                    socket.Connect(host, port);
                    return(socket);
                }
                catch (Exception e)
                {
                    message = e.ToString();
                    throw new JSchException(message);
                }
            }
            String _host = host;
            int    _port = port;

            Socket[] sockp         = new Socket[1];
            Thread   currentThread = Thread.CurrentThread;

            Exception[] ee = new Exception[1];
            message = "";
            createSocketRun runnable = new createSocketRun(sockp, ee, _host, _port);
            Thread          tmp      = new Thread(new ThreadStart(runnable.run));

            tmp.Name = "Opening Socket " + host;
            tmp.Start();
            try
            {
                tmp.Join(timeout);
                message = "timeout: ";
            }
            catch (ThreadInterruptedException)
            {
            }
            if (sockp[0] != null && sockp[0].Connected)
            {
                socket = sockp[0];
            }
            else
            {
                message += "socket is not established";
                if (ee[0] != null)
                {
                    message = ee[0].ToString();
                }
                tmp.Interrupt();
                tmp = null;
                throw new JSchException(message);
            }
            return(socket);
        }