public static void RunExample(String[] arg)
        {
            try
            {
                JSch jsch=new JSch();

                OpenFileDialog chooser = new OpenFileDialog();
                chooser.Title ="Choose your privatekey(ex. ~/.ssh/id_dsa)";
                //chooser.setFileHidingEnabled(false);
                DialogResult returnVal = chooser.ShowDialog();
                if(returnVal == DialogResult.OK)
                {
                    Console.WriteLine("You chose "+
                        chooser.FileName+".");
                    jsch.addIdentity(chooser.FileName
                        //			 , "passphrase"
                        );
                }
                else
                {
                    Console.WriteLine("Error getting key file...");
                    return;
                }
                InputForm inForm = new InputForm();
                inForm.Text = "Enter username@hostname";
                inForm.textBox1.Text = Environment.UserName+"@localhost";

                if (inForm.PromptForInput())
                {
                    String host = inForm.textBox1.Text;
                    String user=host.Substring(0, host.IndexOf('@'));
                    host=host.Substring(host.IndexOf('@')+1);

                    Session session=jsch.getSession(user, host, 22);

                    // username and passphrase will be given via UserInfo interface.
                    UserInfo ui=new MyUserInfo();
                    session.setUserInfo(ui);
                    session.connect();

                    Channel channel=session.openChannel("shell");

                    channel.setInputStream(Console.OpenStandardInput());
                    channel.setOutputStream(Console.OpenStandardOutput());

                    channel.connect();
                }
                inForm.Close();

            }
            catch(Exception e)
            {
                Console.WriteLine(e);
            }
        }
示例#2
0
        public static void RunExample(String[] arg)
        {
            if(arg.Length<3)
            {
                Console.Error.WriteLine(
                    "usage: java KeyGen rsa output_keyfile comment\n"+
                    "       java KeyGen dsa  output_keyfile comment");
                Environment.Exit(-1);
            }
            String _type=arg[0];
            int type=0;
            if(_type.Equals("rsa")){type=KeyPair.RSA;}
            else if(_type.Equals("dsa")){type=KeyPair.DSA;}
            else
            {
                Console.Error.WriteLine(
                    "usage: java KeyGen rsa output_keyfile comment\n"+
                    "       java KeyGen dsa  output_keyfile comment");
                Environment.Exit(-1);
            }
            String filename=arg[1];
            String comment=arg[2];

            JSch jsch=new JSch();

            String passphrase="";
            InputForm passphraseField=new InputForm();
            passphraseField.PasswordField = true;
            Object[] ob={passphraseField};

                passphraseField.Text="Enter passphrase (empty for no passphrase)";
                bool result=passphraseField.PromptForInput();
            if(result)
            {
                passphrase=passphraseField.getText();
            }

            try
            {
                KeyPair kpair=KeyPair.genKeyPair(jsch, type);
                kpair.setPassphrase(passphrase);
                kpair.writePrivateKey(filename);
                kpair.writePublicKey(filename+".pub", comment);
                Console.WriteLine("Finger print: "+kpair.getFingerPrint());
                kpair.dispose();
            }
            catch(Exception e)
            {
                Console.WriteLine(e);
            }
            Environment.Exit(0);
        }
示例#3
0
文件: InputForm.cs 项目: kurhula/t1
 public static string GetUserInput(string title, string devaultValue, bool password)
 {
     Instance.Text          = title;
     Instance.textBox1.Text = devaultValue;
     Instance.PasswordField = password;
     if (Instance.PromptForInput())
     {
         return(Instance.textBox1.Text);
     }
     else
     {
         Console.WriteLine("Canceled by user");
         Environment.Exit(0);
         return(null);
     }
 }
示例#4
0
            public bool promptPassword(String message)
            {
                InputForm passwordField = new InputForm();

                passwordField.Text          = message;
                passwordField.PasswordField = true;

                if (passwordField.PromptForInput())
                {
                    passwd = passwordField.getText();
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
示例#5
0
文件: Sftp.cs 项目: darbio/MTSharpSSH
        public static void Main(String[] arg)
        {
            try
            {
                JSch jsch=new JSch();

                InputForm inForm = new InputForm();
                inForm.Text = "Enter username@hostname";
                inForm.textBox1.Text = Environment.UserName+"@localhost";

                if (!inForm.PromptForInput())
                {
                    Console.WriteLine("Cancelled");
                    return;
                }
                String host = inForm.textBox1.Text;
                String user=host.Substring(0, host.IndexOf('@'));
                host=host.Substring(host.IndexOf('@')+1);

                Session session=jsch.getSession(user, host, 22);

                // username and password will be given via UserInfo interface.
                UserInfo ui=new MyUserInfo();
                session.setUserInfo(ui);

                session.connect();

                Channel channel=session.openChannel("sftp");
                channel.connect();
                ChannelSftp c=(ChannelSftp)channel;

                Stream ins=Console.OpenStandardInput();
                TextWriter outs=Console.Out;

                ArrayList cmds=new ArrayList();
                byte[] buf=new byte[1024];
                int i;
                String str;
                int level=0;

                while(true)
                {
                    outs.Write("sftp> ");
                    cmds.Clear();
                    i=ins.Read(buf, 0, 1024);
                    if(i<=0)break;

                    i--;
                    if(i>0 && buf[i-1]==0x0d)i--;
                    //str=Util.getString(buf, 0, i);
                    //Console.WriteLine("|"+str+"|");
                    int s=0;
                    for(int ii=0; ii<i; ii++)
                    {
                        if(buf[ii]==' ')
                        {
                            if(ii-s>0){ cmds.Add(Util.getString(buf, s, ii-s)); }
                            while(ii<i){if(buf[ii]!=' ')break; ii++;}
                            s=ii;
                        }
                    }
                    if(s<i){ cmds.Add(Util.getString(buf, s, i-s)); }
                    if(cmds.Count==0)continue;

                    String cmd=(String)cmds[0];
                    if(cmd.Equals("quit"))
                    {
                        c.quit();
                        break;
                    }
                    if(cmd.Equals("exit"))
                    {
                        c.exit();
                        break;
                    }
                    if(cmd.Equals("rekey"))
                    {
                        session.rekey();
                        continue;
                    }
                    if(cmd.Equals("compression"))
                    {
                        if(cmds.Count<2)
                        {
                            outs.WriteLine("compression level: "+level);
                            continue;
                        }
                        try
                        {
                            level=int.Parse((String)cmds[1]);
                            Hashtable config=new Hashtable();
                            if(level==0)
                            {
                                config.Add("compression.s2c", "none");
                                config.Add("compression.c2s", "none");
                            }
                            else
                            {
                                config.Add("compression.s2c", "zlib,none");
                                config.Add("compression.c2s", "zlib,none");
                            }
                            session.setConfig(config);
                        }
                        catch{}//(Exception e){}
                        continue;
                    }
                    if(cmd.Equals("cd") || cmd.Equals("lcd"))
                    {
                        if(cmds.Count<2) continue;
                        String path=(String)cmds[1];
                        try
                        {
                            if(cmd.Equals("cd")) c.cd(path);
                            else c.lcd(path);
                        }
                        catch(SftpException e)
                        {
                            Console.WriteLine(e.message);
                        }
                        continue;
                    }
                    if(cmd.Equals("rm") || cmd.Equals("rmdir") || cmd.Equals("mkdir"))
                    {
                        if(cmds.Count<2) continue;
                        String path=(String)cmds[1];
                        try
                        {
                            if(cmd.Equals("rm")) c.rm(path);
                            else if(cmd.Equals("rmdir")) c.rmdir(path);
                            else c.mkdir(path);
                        }
                        catch(SftpException e)
                        {
                            Console.WriteLine(e.message);
                        }
                        continue;
                    }
                    if(cmd.Equals("chgrp") || cmd.Equals("chown") || cmd.Equals("chmod"))
                    {
                        if(cmds.Count!=3) continue;
                        String path=(String)cmds[2];
                        int foo=0;
                        if(cmd.Equals("chmod"))
                        {
                            byte[] bar=Util.getBytes((String)cmds[1]);
                            int k;
                            for(int j=0; j<bar.Length; j++)
                            {
                                k=bar[j];
                                if(k<'0'||k>'7'){foo=-1; break;}
                                foo<<=3;
                                foo|=(k-'0');
                            }
                            if(foo==-1)continue;
                        }
                        else
                        {
                            try{foo=int.Parse((String)cmds[1]);}
                            catch{}//(Exception e){continue;}
                        }
                        try
                        {
                            if(cmd.Equals("chgrp")){ c.chgrp(foo, path); }
                            else if(cmd.Equals("chown")){ c.chown(foo, path); }
                            else if(cmd.Equals("chmod")){ c.chmod(foo, path); }
                        }
                        catch(SftpException e)
                        {
                            Console.WriteLine(e.message);
                        }
                        continue;
                    }
                    if(cmd.Equals("pwd") || cmd.Equals("lpwd"))
                    {
                        str=(cmd.Equals("pwd")?"Remote":"Local");
                        str+=" working directory: ";
                        if(cmd.Equals("pwd")) str+=c.pwd();
                        else str+=c.lpwd();
                        outs.WriteLine(str);
                        continue;
                    }
                    if(cmd.Equals("ls") || cmd.Equals("dir"))
                    {
                        String path=".";
                        if(cmds.Count==2) path=(String)cmds[1];
                        try
                        {
                            ArrayList vv=c.ls(path);
                            if(vv!=null)
                            {
                                for(int ii=0; ii<vv.Count; ii++)
                                {
                                    object obj = vv[ii];
                                    if(obj is ChannelSftp.LsEntry)
                                        outs.WriteLine(vv[ii]);
                                }
                            }
                        }
                        catch(SftpException e)
                        {
                            Console.WriteLine(e.message);
                        }
                        continue;
                    }
                    if(cmd.Equals("lls") || cmd.Equals("ldir"))
                    {
                        String path=".";
                        if(cmds.Count==2) path=(String)cmds[1];
                        try
                        {
                            //java.io.File file=new java.io.File(path);
                            if(!File.Exists(path))
                            {
                                outs.WriteLine(path+": No such file or directory");
                                continue;
                            }
                            if(Directory.Exists(path))
                            {
                                String[] list=Directory.GetDirectories(path);
                                for(int ii=0; ii<list.Length; ii++)
                                {
                                    outs.WriteLine(list[ii]);
                                }
                                continue;
                            }
                            outs.WriteLine(path);
                        }
                        catch(Exception e)
                        {
                            Console.WriteLine(e);
                        }
                        continue;
                    }
                    if(cmd.Equals("get") ||
                        cmd.Equals("get-resume") || cmd.Equals("get-append") ||
                        cmd.Equals("put") ||
                        cmd.Equals("put-resume") || cmd.Equals("put-append")
                        )
                    {
                        if(cmds.Count!=2 && cmds.Count!=3) continue;
                        String p1=(String)cmds[1];
                        //	  String p2=p1;
                        String p2=".";
                        if(cmds.Count==3)p2=(String)cmds[2];
                        try
                        {
                            SftpProgressMonitor monitor=new MyProgressMonitor();
                            if(cmd.StartsWith("get"))
                            {
                                int mode=ChannelSftp.OVERWRITE;
                                if(cmd.Equals("get-resume")){ mode=ChannelSftp.RESUME; }
                                else if(cmd.Equals("get-append")){ mode=ChannelSftp.APPEND; }
                                c.get(p1, p2, monitor, mode);
                            }
                            else
                            {
                                int mode=ChannelSftp.OVERWRITE;
                                if(cmd.Equals("put-resume")){ mode=ChannelSftp.RESUME; }
                                else if(cmd.Equals("put-append")){ mode=ChannelSftp.APPEND; }
                                c.put(p1, p2, monitor, mode);
                            }
                        }
                        catch(SftpException e)
                        {
                            Console.WriteLine(e.message);
                        }
                        continue;
                    }
                    if(cmd.Equals("ln") || cmd.Equals("symlink") || cmd.Equals("rename"))
                    {
                        if(cmds.Count!=3) continue;
                        String p1=(String)cmds[1];
                        String p2=(String)cmds[2];
                        try
                        {
                            if(cmd.Equals("rename")) c.rename(p1, p2);
                            else c.symlink(p1, p2);
                        }
                        catch(SftpException e)
                        {
                            Console.WriteLine(e.message);
                        }
                        continue;
                    }
                    if(cmd.Equals("stat") || cmd.Equals("lstat"))
                    {
                        if(cmds.Count!=2) continue;
                        String p1=(String)cmds[1];
                        SftpATTRS attrs=null;
                        try
                        {
                            if(cmd.Equals("stat")) attrs=c.stat(p1);
                            else attrs=c.lstat(p1);
                        }
                        catch(SftpException e)
                        {
                            Console.WriteLine(e.message);
                        }
                        if(attrs!=null)
                        {
                            outs.WriteLine(attrs);
                        }
                        else
                        {
                        }
                        continue;
                    }
                    if(cmd.Equals("version"))
                    {
                        outs.WriteLine("SFTP protocol version "+c.version());
                        continue;
                    }
                    if(cmd.Equals("help") || cmd.Equals("?"))
                    {
                        outs.WriteLine(help);
                        continue;
                    }
                    outs.WriteLine("unimplemented command: "+cmd);
                }
                session.disconnect();
            }
            catch(Exception e)
            {
                Console.WriteLine(e);
            }
        }
示例#6
0
文件: Sftp.cs 项目: darbio/MTSharpSSH
            public bool promptPassword(String message)
            {
                InputForm inForm = new InputForm();
                inForm.Text = message;
                inForm.PasswordField = true;

                if ( inForm.PromptForInput() )
                {
                    passwd=inForm.getText();
                    return true;
                }
                else{ return false; }
            }
示例#7
0
            public bool promptPassword(String message)
            {
                InputForm passwordField=new InputForm();
                passwordField.Text = message;
                passwordField.PasswordField = true;

                if ( passwordField.PromptForInput() )
                {
                    passwd=passwordField.getText();
                    return true;
                }
                else{ return false; }
            }
示例#8
0
        public static void Main(String[] arg)
        {
            try
            {
                JSch jsch = new JSch();

                InputForm inForm = new InputForm();
                inForm.Text          = "Enter username@hostname";
                inForm.textBox1.Text = Environment.UserName + "@localhost";

                if (!inForm.PromptForInput())
                {
                    Console.WriteLine("Cancelled");
                    return;
                }
                String host = inForm.textBox1.Text;
                String user = host.Substring(0, host.IndexOf('@'));
                host = host.Substring(host.IndexOf('@') + 1);

                Session session = jsch.getSession(user, host, 22);

                // username and password will be given via UserInfo interface.
                UserInfo ui = new MyUserInfo();
                session.setUserInfo(ui);

                session.connect();

                Channel channel = session.openChannel("sftp");
                channel.connect();
                ChannelSftp c = (ChannelSftp)channel;

                Stream     ins  = Console.OpenStandardInput();
                TextWriter outs = Console.Out;

                ArrayList cmds = new ArrayList();
                byte[]    buf  = new byte[1024];
                int       i;
                String    str;
                int       level = 0;

                while (true)
                {
                    outs.Write("sftp> ");
                    cmds.Clear();
                    i = ins.Read(buf, 0, 1024);
                    if (i <= 0)
                    {
                        break;
                    }

                    i--;
                    if (i > 0 && buf[i - 1] == 0x0d)
                    {
                        i--;
                    }
                    //str=Util.getString(buf, 0, i);
                    //Console.WriteLine("|"+str+"|");
                    int s = 0;
                    for (int ii = 0; ii < i; ii++)
                    {
                        if (buf[ii] == ' ')
                        {
                            if (ii - s > 0)
                            {
                                cmds.Add(Util.getString(buf, s, ii - s));
                            }
                            while (ii < i)
                            {
                                if (buf[ii] != ' ')
                                {
                                    break;
                                }
                                ii++;
                            }
                            s = ii;
                        }
                    }
                    if (s < i)
                    {
                        cmds.Add(Util.getString(buf, s, i - s));
                    }
                    if (cmds.Count == 0)
                    {
                        continue;
                    }

                    String cmd = (String)cmds[0];
                    if (cmd.Equals("quit"))
                    {
                        c.quit();
                        break;
                    }
                    if (cmd.Equals("exit"))
                    {
                        c.exit();
                        break;
                    }
                    if (cmd.Equals("rekey"))
                    {
                        session.rekey();
                        continue;
                    }
                    if (cmd.Equals("compression"))
                    {
                        if (cmds.Count < 2)
                        {
                            outs.WriteLine("compression level: " + level);
                            continue;
                        }
                        try
                        {
                            level = int.Parse((String)cmds[1]);
                            Hashtable config = new Hashtable();
                            if (level == 0)
                            {
                                config.Add("compression.s2c", "none");
                                config.Add("compression.c2s", "none");
                            }
                            else
                            {
                                config.Add("compression.s2c", "zlib,none");
                                config.Add("compression.c2s", "zlib,none");
                            }
                            session.setConfig(config);
                        }
                        catch {}                       //(Exception e){}
                        continue;
                    }
                    if (cmd.Equals("cd") || cmd.Equals("lcd"))
                    {
                        if (cmds.Count < 2)
                        {
                            continue;
                        }
                        String path = (String)cmds[1];
                        try
                        {
                            if (cmd.Equals("cd"))
                            {
                                c.cd(path);
                            }
                            else
                            {
                                c.lcd(path);
                            }
                        }
                        catch (SftpException e)
                        {
                            Console.WriteLine(e.message);
                        }
                        continue;
                    }
                    if (cmd.Equals("rm") || cmd.Equals("rmdir") || cmd.Equals("mkdir"))
                    {
                        if (cmds.Count < 2)
                        {
                            continue;
                        }
                        String path = (String)cmds[1];
                        try
                        {
                            if (cmd.Equals("rm"))
                            {
                                c.rm(path);
                            }
                            else if (cmd.Equals("rmdir"))
                            {
                                c.rmdir(path);
                            }
                            else
                            {
                                c.mkdir(path);
                            }
                        }
                        catch (SftpException e)
                        {
                            Console.WriteLine(e.message);
                        }
                        continue;
                    }
                    if (cmd.Equals("chgrp") || cmd.Equals("chown") || cmd.Equals("chmod"))
                    {
                        if (cmds.Count != 3)
                        {
                            continue;
                        }
                        String path = (String)cmds[2];
                        int    foo  = 0;
                        if (cmd.Equals("chmod"))
                        {
                            byte[] bar = Util.getBytes((String)cmds[1]);
                            int    k;
                            for (int j = 0; j < bar.Length; j++)
                            {
                                k = bar[j];
                                if (k < '0' || k > '7')
                                {
                                    foo = -1; break;
                                }
                                foo <<= 3;
                                foo  |= (k - '0');
                            }
                            if (foo == -1)
                            {
                                continue;
                            }
                        }
                        else
                        {
                            try{ foo = int.Parse((String)cmds[1]); }
                            catch {}                           //(Exception e){continue;}
                        }
                        try
                        {
                            if (cmd.Equals("chgrp"))
                            {
                                c.chgrp(foo, path);
                            }
                            else if (cmd.Equals("chown"))
                            {
                                c.chown(foo, path);
                            }
                            else if (cmd.Equals("chmod"))
                            {
                                c.chmod(foo, path);
                            }
                        }
                        catch (SftpException e)
                        {
                            Console.WriteLine(e.message);
                        }
                        continue;
                    }
                    if (cmd.Equals("pwd") || cmd.Equals("lpwd"))
                    {
                        str  = (cmd.Equals("pwd")?"Remote":"Local");
                        str += " working directory: ";
                        if (cmd.Equals("pwd"))
                        {
                            str += c.pwd();
                        }
                        else
                        {
                            str += c.lpwd();
                        }
                        outs.WriteLine(str);
                        continue;
                    }
                    if (cmd.Equals("ls") || cmd.Equals("dir"))
                    {
                        String path = ".";
                        if (cmds.Count == 2)
                        {
                            path = (String)cmds[1];
                        }
                        try
                        {
                            ArrayList vv = c.ls(path);
                            if (vv != null)
                            {
                                for (int ii = 0; ii < vv.Count; ii++)
                                {
                                    object obj = vv[ii];
                                    if (obj is ChannelSftp.LsEntry)
                                    {
                                        outs.WriteLine(vv[ii]);
                                    }
                                }
                            }
                        }
                        catch (SftpException e)
                        {
                            Console.WriteLine(e.message);
                        }
                        continue;
                    }
                    if (cmd.Equals("lls") || cmd.Equals("ldir"))
                    {
                        String path = ".";
                        if (cmds.Count == 2)
                        {
                            path = (String)cmds[1];
                        }
                        try
                        {
                            //java.io.File file=new java.io.File(path);
                            if (!File.Exists(path))
                            {
                                outs.WriteLine(path + ": No such file or directory");
                                continue;
                            }
                            if (Directory.Exists(path))
                            {
                                String[] list = Directory.GetDirectories(path);
                                for (int ii = 0; ii < list.Length; ii++)
                                {
                                    outs.WriteLine(list[ii]);
                                }
                                continue;
                            }
                            outs.WriteLine(path);
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine(e);
                        }
                        continue;
                    }
                    if (cmd.Equals("get") ||
                        cmd.Equals("get-resume") || cmd.Equals("get-append") ||
                        cmd.Equals("put") ||
                        cmd.Equals("put-resume") || cmd.Equals("put-append")
                        )
                    {
                        if (cmds.Count != 2 && cmds.Count != 3)
                        {
                            continue;
                        }
                        String p1 = (String)cmds[1];
                        //	  String p2=p1;
                        String p2 = ".";
                        if (cmds.Count == 3)
                        {
                            p2 = (String)cmds[2];
                        }
                        try
                        {
                            SftpProgressMonitor monitor = new MyProgressMonitor();
                            if (cmd.StartsWith("get"))
                            {
                                int mode = ChannelSftp.OVERWRITE;
                                if (cmd.Equals("get-resume"))
                                {
                                    mode = ChannelSftp.RESUME;
                                }
                                else if (cmd.Equals("get-append"))
                                {
                                    mode = ChannelSftp.APPEND;
                                }
                                c.get(p1, p2, monitor, mode);
                            }
                            else
                            {
                                int mode = ChannelSftp.OVERWRITE;
                                if (cmd.Equals("put-resume"))
                                {
                                    mode = ChannelSftp.RESUME;
                                }
                                else if (cmd.Equals("put-append"))
                                {
                                    mode = ChannelSftp.APPEND;
                                }
                                c.put(p1, p2, monitor, mode);
                            }
                        }
                        catch (SftpException e)
                        {
                            Console.WriteLine(e.message);
                        }
                        continue;
                    }
                    if (cmd.Equals("ln") || cmd.Equals("symlink") || cmd.Equals("rename"))
                    {
                        if (cmds.Count != 3)
                        {
                            continue;
                        }
                        String p1 = (String)cmds[1];
                        String p2 = (String)cmds[2];
                        try
                        {
                            if (cmd.Equals("rename"))
                            {
                                c.rename(p1, p2);
                            }
                            else
                            {
                                c.symlink(p1, p2);
                            }
                        }
                        catch (SftpException e)
                        {
                            Console.WriteLine(e.message);
                        }
                        continue;
                    }
                    if (cmd.Equals("stat") || cmd.Equals("lstat"))
                    {
                        if (cmds.Count != 2)
                        {
                            continue;
                        }
                        String    p1    = (String)cmds[1];
                        SftpATTRS attrs = null;
                        try
                        {
                            if (cmd.Equals("stat"))
                            {
                                attrs = c.stat(p1);
                            }
                            else
                            {
                                attrs = c.lstat(p1);
                            }
                        }
                        catch (SftpException e)
                        {
                            Console.WriteLine(e.message);
                        }
                        if (attrs != null)
                        {
                            outs.WriteLine(attrs);
                        }
                        else
                        {
                        }
                        continue;
                    }
                    if (cmd.Equals("version"))
                    {
                        outs.WriteLine("SFTP protocol version " + c.version());
                        continue;
                    }
                    if (cmd.Equals("help") || cmd.Equals("?"))
                    {
                        outs.WriteLine(help);
                        continue;
                    }
                    outs.WriteLine("unimplemented command: " + cmd);
                }
                session.disconnect();
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }
            public bool promptPassphrase(String message)
            {
                InputForm inForm = new InputForm();
                inForm.Text = message;
                inForm.PasswordField = true;

                if ( inForm.PromptForInput() )
                {
                    passphrase=inForm.textBox1.Text;
                    inForm.Close();
                    return true;
                }
                else
                {
                    inForm.Close();
                    return false;
                }
            }
示例#10
0
        public static void RunExample(String[] arg)
        {
            try
            {
                JSch jsch=new JSch();

                OpenFileDialog chooser = new OpenFileDialog();
                chooser.Title = "Choose your known_hosts(ex. ~/.ssh/known_hosts)";
                //chooser.setFileHidingEnabled(false);
                DialogResult returnVal = chooser.ShowDialog();
                if(returnVal == DialogResult.OK)
                {
                    Console.WriteLine("You chose "+
                        chooser.FileName+".");
                    jsch.setKnownHosts(chooser.FileName);
                }
                else
                {
                    Console.WriteLine("Error getting host file...");
                    return;
                }

                HostKeyRepository hkr=jsch.getHostKeyRepository();
                HostKey[] hks=hkr.getHostKey();
                if(hks!=null)
                {
                    Console.WriteLine("Host keys in "+hkr.getKnownHostsRepositoryID());
                    for(int i=0; i<hks.Length; i++)
                    {
                        HostKey hk=hks[i];
                        Console.WriteLine(hk.getHost()+" "+
                            hk.getType()+" "+
                            hk.getFingerPrint(jsch));
                    }
                    Console.WriteLine("");
                }

                InputForm inForm = new InputForm();
                inForm.Text = "Enter username@hostname";
                inForm.textBox1.Text = Environment.UserName+"@localhost";

                if (inForm.PromptForInput())
                {
                    String host = inForm.textBox1.Text;
                    String user=host.Substring(0, host.IndexOf('@'));
                    host=host.Substring(host.IndexOf('@')+1);

                    Session session=jsch.getSession(user, host, 22);

                    // username and password will be given via UserInfo interface.
                    UserInfo ui=new MyUserInfo();
                    session.setUserInfo(ui);

                    session.connect();

                    HostKey hk=session.getHostKey();
                    Console.WriteLine("HostKey: "+
                        hk.getHost()+" "+
                        hk.getType()+" "+
                        hk.getFingerPrint(jsch));

                    Channel channel=session.openChannel("shell");

                    channel.setInputStream(Console.OpenStandardInput());
                    channel.setOutputStream(Console.OpenStandardOutput());

                    channel.connect();
                }
                inForm.Close();

            }
            catch(Exception e)
            {
                Console.WriteLine(e);
            }
        }
        public static void RunExample(String[] arg)
        {
            if(arg.Length!=1)
            {
                Console.WriteLine("usage: java ChangePassphrase private_key");
                Environment.Exit(-1);
            }

            JSch jsch=new JSch();

            String pkey=arg[0];

            try
            {
                KeyPair kpair=KeyPair.load(jsch, pkey);

                Console.WriteLine(pkey+" has "+(kpair.isEncrypted()?"been ":"not been ")+"encrypted");

                String passphrase="";
                InputForm passphraseField = null;

                while(kpair.isEncrypted())
                {
                    passphraseField=new InputForm();
                    passphraseField.PasswordField = true;

                    if(!passphraseField.PromptForInput())
                    {
                        Environment.Exit(-1);
                    }
                    passphrase=passphraseField.getText();
                    if(!kpair.decrypt(passphrase))
                    {
                        Console.WriteLine("failed to decrypt "+pkey);
                    }
                    else
                    {
                        Console.WriteLine(pkey+" is decrypted.");
                    }
                }

                passphrase="";

                passphraseField=new InputForm();
                passphraseField.PasswordField = true;

                if(!passphraseField.PromptForInput())
                {
                    Environment.Exit(-1);
                }
                passphrase=passphraseField.getText();

                kpair.setPassphrase(passphrase);
                kpair.writePrivateKey(pkey);
                kpair.dispose();
            }
            catch(Exception e)
            {
                Console.WriteLine(e);
            }
            Environment.Exit(0);
        }