#title SSIS에서 SSH 명령 https://github.com/sshnet/SSH.NET/releases {{{ #region Namespaces using System; using System.Data; using Microsoft.SqlServer.Dts.Runtime; using System.Windows.Forms; using Renci.SshNet; using System.IO; using System.Threading; using System.Text; using System.Collections.Generic; using System.Text.RegularExpressions; #endregion ... public void Main() { // TODO: Add your code here var svr = Dts.Variables["User::ssh_svr"].Value.ToString(); //접속할 서버명 var port = (int)Dts.Variables["User::ssh_port"].Value; //TCP 포트 var id = Dts.Variables["User::ssh_id"].Value.ToString(); //접속id var pw = Dts.Variables["User::ssh_pw"].Value.ToString(); //접속PW var cmd_string = Dts.Variables["User::ssh_cmd"].Value.ToString();//명령어 //System.Windows.Forms.MessageBox.Show(svr); using (var client = new SshClient(svr, port, id, pw)) { client.Connect(); //client.RunCommand(cmd_string); //cmd_string = "hadoop fs -rm -r /user/hive/warehouse/test.db/test"; cmd_string = "hadoop fs -rm /user/hive/warehouse/test.db/test/*"; var command = client.CreateCommand(cmd_string); command.Execute(); string cmd_out = command.Result.ToString() + command.Error.ToString(); int cmd_sts = command.ExitStatus; //MessageBox.Show(cmd_out); //MessageBox.Show(cmd_sts); Dts.Variables["User::ssh_result"].Value = cmd_out; //실행결과 Dts.Variables["User::ssh_status"].Value = cmd_sts; //실행상태 client.Disconnect(); } Dts.TaskResult = (int)ScriptResults.Success; } ... } } }}} 키 이용 puttygen.exe로 메뉴의 Conversions -> Export OpenSSH key 로 변환한다. * https://stackoverflow.com/questions/55378001/renci-sshnet-common-sshexception-invalid-private-key-file-when-loading-ssh-pr * https://gist.github.com/piccaso/d963331dcbf20611b094 대충 이렇게 {{{ using (var sshclient = new SshClient(ConnNfo)){ sshclient.Connect(); using(var cmd = sshclient.CreateCommand("ls")){ cmd.Execute(); Console.WriteLine("Command>" + cmd.CommandText); //명령어 Console.WriteLine("Command>" + cmd.Result); //결과 Console.WriteLine("Command>" + cmd.Error); //에러 Console.WriteLine("Return Value = {0}", cmd.ExitStatus); } sshclient.Disconnect(); } }}}