Ejemplo n.º 1
0
        protected override jsch::Session ConnectImpl()
        {
            if (this.gwchain.Count == 0)
            {
                return(null);
            }
            // register identities
            this.m_jsch = new jsch::JSch();
            foreach (SshUserData user in gwchain)
            {
                if (user.useIdentityFile && user.idtt != "")
                {
                    m_jsch.addIdentity(user.idtt, user.psph);
                }
            }

            // logins
            jsch::Session gwsess = null;

            foreach (SshUserData user in gwchain)
            {
                gwsess = create_session(user, gwsess);
            }

            return(gwsess);
        }
Ejemplo n.º 2
0
        public void Disconnect()
        {
            lock (this.sync_connect){
                if (this.sess == null)
                {
                    return;
                }

                // 処理中断
                foreach (jsch::ChannelSftp channel in this.channels.Values)
                {
                    channel.exit();
                }
                msg.Write(1, ". Waiting...");
                System.Threading.Thread.Sleep(1000);

                // 接続切断
                msg.Write(1, ". Disconnecting");
                Program.Background -= this.connection_hold;
                this.DisconnectImpl();

                // 資源解放
                resources.Clear();
                this.channels.Clear();
                this.sess = null;
                msg.Write(1, ". Disconnected");
            }
        }
Ejemplo n.º 3
0
        public static void ssh_test1()
        {
            SshUserData data1 = new SshUserData();

            data1.user = "******";
            data1.host = "tkynt2.phys.s.u-tokyo.ac.jp";
            data1.port = 22;
            data1.pass = "";

            System.Collections.Hashtable config = new System.Collections.Hashtable();
            config["StrictHostKeyChecking"] = "no";

            SshfsMessage mess1 = new SshfsMessage("[]");

            jsch::JSch    jsch  = new Tamir.SharpSsh.jsch.JSch();
            jsch::Session sess1 = jsch.getSession(data1.user, data1.host, data1.port);

            sess1.setConfig(config);
            //sess1.setUserInfo(new DokanSSHFS.DokanUserInfo(data1.pass,null));
            sess1.setUserInfo(new SshLoginInfo(mess1, data1));
            sess1.setPassword(data1.pass);
            sess1.connect();

            jsch::ChannelExec ch_e = (jsch::ChannelExec)sess1.openChannel("exec");

            ch_e.setCommand("cat");
            ch_e.setOutputStream(System.Console.OpenStandardOutput(), true);
            Tamir.SharpSsh.java.io.InputStream ins = ch_e.getInputStream();
            ch_e.connect();

            System.Console.WriteLine("ls -al ~/");
            System.IO.StreamWriter sw = new System.IO.StreamWriter(ins);
            sw.WriteLine("hello");

            //System.Threading.Thread.Sleep(2000);
            //System.Console.WriteLine("comp.");

            sw.Close();
            ins.close();

            ch_e.disconnect();
            sess1.disconnect();
        }
Ejemplo n.º 4
0
        //==========================================================================
        //	接続と切断
        //==========================================================================
        jsch::Session create_session(SshUserData user, jsch::Session gateway)
        {
            msg.Write(1, ". Connecting {0}@{1}", user.user, user.host);

            // setting
            jsch::Session session = m_jsch.getSession(user.user, user.host, user.port);

            session.setConfig(SSH_CONFIG);
            session.setUserInfo(new SshLoginInfo(this.msg, user));
            session.setPassword(user.pass);
            if (gateway != null)
            {
                GatewayProxy proxy = new GatewayProxy(gateway);
                resources.Add(proxy);
                session.setProxy(proxy);
            }

            // connect
            session.connect();
            resources.Add(session);
            return(session);
        }
Ejemplo n.º 5
0
        //--------------------------------------------------------------------------
        //	接続・切断
        //--------------------------------------------------------------------------
        protected override jsch::Session ConnectImpl()
        {
            msg.Write(1, ". Connecting...");
            this.m_jsch = new jsch::JSch();

            if (data.useIdentityFile && data.idtt != "")
            {
                this.m_jsch.addIdentity(data.idtt, data.psph);
            }

            jsch::Session sess = this.m_jsch.getSession(data.user, data.host, data.port);

            sess = this.m_jsch.getSession(data.user, data.host, data.port);
            sess.setConfig(this.config);
            sess.setUserInfo(new SshLoginInfo(this.msg, this.data));
            sess.setPassword(data.pass);
            sess.connect();
            this.resources.Add(sess);

            msg.Write(1, ". Connected");
            return(sess);
        }
Ejemplo n.º 6
0
        public bool Connect()
        {
            lock (this.sync_connect){
                if (this.sess != null)
                {
                    return(true);
                }

                try{
                    this.sess = this.ConnectImpl();
                    if (sess == null)
                    {
                        return(false);
                    }

                    Program.Background += this.connection_hold;
                    return(true);
                }catch (System.Exception e1) {
                    resources.Clear();
                    msg.ReportErr(e1);
                    return(false);
                }
            }
        }
Ejemplo n.º 7
0
 public GatewayProxy(jsch::Session parent)
 {
     ch_e = (jsch::ChannelExec)parent.openChannel("exec");
 }
Ejemplo n.º 8
0
 public SessionDisposer(jsch::Session obj)
 {
     this.obj = obj;
 }
Ejemplo n.º 9
0
 public void Add(jsch::Session session)
 {
     this.Add(new SessionDisposer(session));
 }
Ejemplo n.º 10
0
        public static void ssh_test2()
        {
            SshUserData data1 = new SshUserData();

            data1.user = "******";
            data1.host = "tkynt2.phys.s.u-tokyo.ac.jp";
            data1.port = 22;
            data1.pass = "";

            System.Collections.Hashtable config = new System.Collections.Hashtable();
            config["StrictHostKeyChecking"] = "no";

            SshfsMessage mess1 = new SshfsMessage("[]");

            jsch::JSch    jsch  = new Tamir.SharpSsh.jsch.JSch();
            jsch::Session sess1 = jsch.getSession(data1.user, data1.host, data1.port);

            sess1.setConfig(config);
            //sess1.setUserInfo(new DokanSSHFS.DokanUserInfo(data1.pass,null));
            sess1.setUserInfo(new SshLoginInfo(mess1, data1));
            sess1.setPassword(data1.pass);
            sess1.connect();

            //MyProx proxy=new MyProx(sess1);

            //SshUserData data2=new SshUserData();
            //data2.user="******";
            //data2.host="127.0.0.1";
            //data2.port=50022;
            //data2.pass="";
            //jsch::Session sess2=jsch.getSession(data2.user,data2.host,data2.port);
            //sess2.setConfig(config);
            //sess2.setUserInfo(new mwg.Sshfs.SshLoginInfo(mess1,data2));
            //sess2.setPassword(data2.pass);
            //sess2.setProxy(proxy);
            //sess2.connect();

            System.Console.WriteLine("cat");
            jsch::ChannelExec ch_e = (jsch::ChannelExec)sess1.openChannel("exec");

            ch_e.setCommand("cat");
            ch_e.setOutputStream(System.Console.OpenStandardOutput(), true);
            System.IO.Stream ins = ch_e.getOutputStream();
            ch_e.connect();


            System.Threading.Thread.Sleep(2000);
            System.Console.WriteLine("hello");
            ins.WriteByte((byte)'h');
            ins.WriteByte((byte)'e');
            ins.WriteByte((byte)'l');
            ins.WriteByte((byte)'l');
            ins.WriteByte((byte)'o');
            ins.WriteByte((byte)'\n');
            ins.Flush();
            //System.Threading.Thread.Sleep(2000);

            System.Threading.Thread.Sleep(2000);
            System.IO.StreamWriter sw = new System.IO.StreamWriter(ins);
            System.Console.WriteLine("test"); sw.WriteLine("test"); sw.Flush();
            System.Threading.Thread.Sleep(2000);
            System.Console.WriteLine("world"); sw.WriteLine("world"); sw.Flush();
            System.Threading.Thread.Sleep(2000);
            for (int i = 0; i < 5; i++)
            {
                System.Console.WriteLine("count={0}", i);
                sw.WriteLine("count={0}", i);
                sw.Flush();
                System.Threading.Thread.Sleep(2000);
            }
            for (int i = 5; i < 20; i++)
            {
                System.Console.WriteLine("count={0}", i);
                sw.WriteLine("count={0}", i);
                sw.Flush();
            }
            System.Threading.Thread.Sleep(2000);
            sw.Close();

            ins.Close();
            System.Console.WriteLine("comp.");

            ch_e.disconnect();
            //sess2.disconnect();
            sess1.disconnect();
        }
Ejemplo n.º 11
0
 public MyProx(jsch::Session parent)
 {
     System.Console.WriteLine("ssh...");
     ch_e = (jsch::ChannelExec)parent.openChannel("exec");
 }