Beispiel #1
0
        /// <summary>
        /// Get input from the user
        /// </summary>
        public static SshConnectionInfo GetInput()
        {
            SshConnectionInfo info = new SshConnectionInfo();

            Console.Write("Enter Remote Host: ");
            info.Host = Console.ReadLine();
            Console.Write("Enter Username: "******"Use publickey authentication? [Yes|No] :");
            string resp = Console.ReadLine();

            if (resp.ToLower().StartsWith("y"))
            {
                Console.Write("Enter identity key filename: ");
                info.IdentityFile = Console.ReadLine();
            }
            else
            {
                Console.Write("Enter Password: ");
                info.Pass = Console.ReadLine();
            }
            Console.WriteLine();
            return(info);
        }
Beispiel #2
0
        public static void RunSsh(SshConnectionInfo input)
        {
            try {
                SshShell shell = new SshShell(input.Host, input.User);
                if (input.Pass != null)
                {
                    shell.Password = input.Pass;
                }
                if (input.IdentityFile != null)
                {
                    shell.AddIdentityFile(input.IdentityFile);
                }

                //This statement must be prior to connecting
                shell.RedirectToConsole();

                Console.Write("Connecting...");
                shell.Connect();
                Console.WriteLine("OK");

                while (shell.ShellOpened)
                {
                    System.Threading.Thread.Sleep(500);
                }
                Console.Write("Disconnecting...");
                shell.Close();
                Console.WriteLine("OK");
            }
            catch (Exception e) {
                Console.WriteLine(e.Message);
            }
        }
Beispiel #3
0
        public static void RunExample()
        {
            try {
                SshConnectionInfo       input = Util.GetInput();
                string                  proto = GetProtocol();
                SshTransferProtocolBase sshCp;

                if (proto.Equals("scp"))
                {
                    sshCp = new Scp(input.Host, input.User);
                }
                else
                {
                    sshCp = new Sftp(input.Host, input.User);
                }

                if (input.Pass != null)
                {
                    sshCp.Password = input.Pass;
                }
                if (input.IdentityFile != null)
                {
                    sshCp.AddIdentityFile(input.IdentityFile);
                }
                sshCp.OnTransferStart    += new FileTransferEvent(sshCp_OnTransferStart);
                sshCp.OnTransferProgress += new FileTransferEvent(sshCp_OnTransferProgress);
                sshCp.OnTransferEnd      += new FileTransferEvent(sshCp_OnTransferEnd);

                Console.Write("Connecting...");
                sshCp.Connect();
                Console.WriteLine("OK");

                while (true)
                {
                    string direction = GetTransferDirection();
                    if (direction.Equals("to"))
                    {
                        string lfile = GetArg("Enter local file ['Enter to cancel']");
                        if (lfile == "")
                        {
                            break;
                        }
                        string rfile = GetArg("Enter remote file ['Enter to cancel']");
                        if (rfile == "")
                        {
                            break;
                        }
                        sshCp.Put(lfile, rfile);
                    }
                    else
                    {
                        string rfile = GetArg("Enter remote file ['Enter to cancel']");
                        if (rfile == "")
                        {
                            break;
                        }
                        string lpath = GetArg("Enter local path ['Enter to cancel']");
                        if (lpath == "")
                        {
                            break;
                        }
                        sshCp.Get(rfile, lpath);
                    }
                }

                Console.Write("Disconnecting...");
                sshCp.Close();
                Console.WriteLine("OK");
            }
            catch (Exception e) {
                Console.WriteLine(e.Message);
            }
        }
Beispiel #4
0
        /*
         *
         */
        public static void Main(String[] argv)
        {
            SshConnectionInfo coninfo       = null;
            SshConnectionInfo globalconinfo = new SshConnectionInfo();

            int    optch;
            Getopt getopt = new Getopt();

            while ((optch = getopt.getopt(argv, "Bhko:sV46CD:H:K:L:NP:R:S:TW:Z:d:i:l:m:tvw:z:")) != -1)
            {
                switch (optch)
                {
                case 'B':                                                       /* --batch */
                    /* FIXME: */
                    break;

                case 'h':                                                       /* --help */
                case '?':
                    usage();
                    Environment.Exit(0);
                    break;

                case 'k':                                                       /* --pgpfp */
                    /* FIXME: */
                    Environment.Exit(1);
                    break;

                case 'o':
                    /* FIXME: */
                    break;

                case 's':
                    /* FIXME: Save Status to write to conf later. */
                    break;

                case 'V':                                                       /* --version */
                    version();
                    break;

                case '4':
                    /* FIXME: */
                    break;

                case '6':
                    /* FIXME: */
                    break;

                case 'C':
                    /* FIXME: */
                    break;

                case 'H':                                                       /* --hostkey key */
                    /* FIXME: */
                    break;

                case 'K':                                                       /* --loghost logical-host-name */
                    /* FIXME: */
                    break;

                case 'N':
                    /* FIXME: */
                    break;

                case 'P':
                    /* FIXME: */
                    break;

                case 'S':                                                       /* --load filename */
                    /* FIXME: */
                    break;

                case 'T':
                    /* FIXME: */
                    break;

                case 'Z':                                                       /* --sshrawlog filename  */
                    /* FIXME: */
                    break;

                case 'd':                                                       /* --sessionlog filename */
                    /* FIXME: */
                    break;

                case 'i':
                    /* FIXME: */
                    break;

                case 'l':
                    /* FIXME: */
                    break;

                case 'm':
                    /* FIXME: */
                    break;

                case 't':
                    /* FIXME: */
                    break;

                case 'v':
                    /* FIXME: */
                    break;

                case 'w':                                                       /* --pw password */
                    globalconinfo.Pass = getopt.optarg;
                    break;

                case 'z':                                                       /* --sshlog filename */
                    /* FIXME: */
                    break;

                default:
                    Console.Error.Write("{0}: unknown option \"{1}\"\n", Env.appname, optch);
                    break;
                }
            }

            //Console.OutputEncoding = System.Text.Encoding.UTF8;
            //Console.OutputEncoding = Encoding.GetEncoding(932);
            //Console.OutputEncoding = Encoding.GetEncoding("Shift_JIS");

            Int32 argidx = getopt.optind;

            while (argidx < argv.Length)
            {
                String p = argv[argidx];
                if (p.Length > 0)
                {
                    if (coninfo == null)
                    {
                        coninfo = new SshConnectionInfo(p);
                    }
                    else
                    {
                    }
                }
                argidx++;
            }

            if (coninfo == null)
            {
                usage();
                Environment.Exit(0);
            }
            if (coninfo.Pass == null)
            {
                coninfo.Pass = globalconinfo.Pass;
            }
            RunSsh(coninfo);
        }