Exemplo n.º 1
0
 public SshGateSession(SshUserData user1, SshUserData user2, ISftpAccount account)
     : base(account, user2.Prompt)
 {
     this.gwchain = new Gen::List <SshUserData>();
     this.gwchain.Add(user1);
     this.gwchain.Add(user2);
 }
Exemplo n.º 2
0
        public static void ssh_test()
        {
            SshUserData data1 = new SshUserData();

            data1.user = "******";
            //data1.host="tkynt2.phys.s.u-tokyo.ac.jp";
            data1.host            = "192.168.0.104";
            data1.port            = 50422;
            data1.pass            = "";
            data1.useIdentityFile = true;
            data1.idtt            = @"C:\usr\cygwin\home\koichi\.ssh\id_rsa-padparadscha@gauge";
            data1.psph            = "";
            ssh_test1(data1);
        }
Exemplo n.º 3
0
        // 参考: https://gist.github.com/piccaso/d963331dcbf20611b094 わかりやすい
        public static void ssh_test1(SshUserData data1)
        {
            ConnectionInfo info = CreateConnectionInfo(data1);

            using (var sshclient = new SshClient(info)){
                sshclient.Connect();

                //using(var cmd = sshclient.CreateCommand("mkdir -p /tmp/uploadtest && chmod +rw /tmp/uploadtest")){
                using (var cmd = sshclient.CreateCommand("(exit 12)")){
                    cmd.Execute();
                    System.Console.WriteLine("Command>" + cmd.CommandText);
                    System.Console.WriteLine("Return Value = {0}", cmd.ExitStatus);
                }

                sshclient.Disconnect();
            }

            System.Console.WriteLine("done");
        }
Exemplo n.º 4
0
        static ConnectionInfo CreateConnectionInfo(SshUserData data)
        {
            // create Authentication methods
            Gen::List <AuthenticationMethod> auth = new Gen::List <AuthenticationMethod>();

            if (data.pass != null && data.pass != "")
            {
                // Password based Authentication
                auth.Add(new PasswordAuthenticationMethod(data.user, data.pass));
            }
            if (data.useIdentityFile && data.idtt != "")
            {
                // Key Based Authentication (using keys in OpenSSH Format)
                auth.Add(new PrivateKeyAuthenticationMethod(data.user, new PrivateKeyFile[] {
                    new PrivateKeyFile(data.idtt, data.psph)
                }));
            }
            return(new ConnectionInfo(data.host, data.port, data.user, auth.ToArray()));
        }
Exemplo n.º 5
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();
        }
Exemplo n.º 6
0
        //==========================================================================
        // ISerializable
        //==========================================================================
        SftpAccount(Ser::SerializationInfo info, Ser::StreamingContext context)
        {
            this.name = info.GetString("name");
            this.data = (SshUserData)info.GetValue("data", typeof(SshUserData));

            SerializationInfoReader reader = new SerializationInfoReader(info);

            reader.GetValue("offline", out this.s_offline, false);
            reader.GetValue("rootdir", out this.rootdir, ".");
            reader.GetValue("s_readonly", out this.s_readonly, false);
            reader.GetValue("s_reconnect_count", out this.s_reconnect_count, 1);
            reader.GetValue("s_discon_interval", out this.s_discon_interval, 300);
            reader.GetValue("s_beat_interval", out this.s_beat_interval, 60);
            int symlink;

            if (reader.GetValue("symlink", out symlink))
            {
                this.symlink = (SftpSymlink)symlink;
            }
            reader.GetValue("s_enabled", out this.s_enabled, true);
        }
Exemplo n.º 7
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);
        }
Exemplo n.º 8
0
        public static void ssh_test2(SshUserData data1)
        {
            ConnectionInfo info = CreateConnectionInfo(data1);

            using (var ssh = new SshClient(info)){
                ssh.Connect();

                using (ShellStream stream = ssh.CreateShellStream("dumb", 80, 24, 800, 600, 1024)){
                    var writer = new System.IO.StreamWriter(stream);
                    var reader = new System.IO.StreamReader(stream);
                    writer.WriteLine("ls -la ~/");
                    writer.WriteLine("echo;echo MWGVFS_EOF");
                    writer.Flush();

                    for (;;)
                    {
                        string line;
                        if (stream.Length == 0)
                        {
                            System.Threading.Thread.Sleep(50);
                        }
                        else if ((line = reader.ReadLine()) != null)
                        {
                            if (line == "MWGVFS_EOF")
                            {
                                break;
                            }
                            System.Console.WriteLine(line);
                        }
                    }
                }

                ssh.Disconnect();
            }

            System.Console.WriteLine("done");
        }
Exemplo n.º 9
0
 public void AddUserData(SshUserData user)
 {
     this.gwchain.Add(user);
 }
Exemplo n.º 10
0
 public SftpAccount(string name, SshUserData data)
 {
     this.name = name;
     this.data = data;
 }
Exemplo n.º 11
0
 public SftpAccount(string name)
 {
     this.name = name;
     this.data = new SshUserData();
 }
Exemplo n.º 12
0
 public SshSession(SshUserData data, ISftpAccount account) : base(account, data.Prompt)
 {
     this.data   = data;
     this.config = new System.Collections.Hashtable(SSH_CONFIG);
 }
Exemplo n.º 13
0
 public SshLoginInfo(SshfsMessage message, SshUserData user)
 {
     this.msg  = message;
     this.pass = user.pass;
     this.psph = user.psph;
 }
Exemplo n.º 14
0
 public SftpFsOperation(SshUserData userdata, ISftpAccount account)
     : this(new SshSession(userdata, account), account)
 {
 }
Exemplo n.º 15
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();
        }