예제 #1
0
        public SSHTool(SSHOptions _options, bool _verbose)
        {
            this.options = _options;
            this.verbose = _verbose;

            AuthenticationMethod authentication;

            if (options.PrivateKeyFile != null)
            {
                authentication = new PrivateKeyAuthenticationMethod(options.Username,
                                                                    new PrivateKeyFile[]
                {
                    new PrivateKeyFile(options.PrivateKeyFile, options.Password)
                }
                                                                    );
            }
            else
            {
                authentication = new PasswordAuthenticationMethod(options.Username, options.Password);
            }

            connectionInfo = new ConnectionInfo(options.Hostname, options.Port, options.Username, authentication);

            sshclient  = new SshClient(connectionInfo);
            sftpclient = new SftpClient(connectionInfo);
        }
예제 #2
0
        static bool CreateSample(CommandlineOptions Options)
        {
            Console.WriteLine("Creating empty config file....");
            SSHOptions sSHOptions = new SSHOptions
            {
                Hostname       = "my.host.sample",
                Port           = 22,
                Localpath      = @"C:\MyRepro\bin\publish\",
                Remotepath     = @"/home/user/sample",
                Username       = "******",
                Password       = "******",
                PrivateKeyFile = null,
                PreCommand     = new List <string> {
                    "precommand1", "precommand2"
                },
                PostCommand = new List <string> {
                    "postcommand1", "postcommand2"
                },
                Excludefiles = new List <string> {
                    "appsettings.json", "*.txt"
                }
            };

            try
            {
                Directory.CreateDirectory(Path.GetDirectoryName(Options.ConfigurationFile));
                using (System.IO.StreamWriter file = new System.IO.StreamWriter(Options.ConfigurationFile))
                {
                    file.Write(JsonConvert.SerializeObject(sSHOptions, Formatting.Indented));
                }
                Console.WriteLine("Configuration written: " + Options.ConfigurationFile);
            }
            catch
            {
                Console.WriteLine("Error writing config file!");
                return(false);
            }
            return(true);
        }