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;
}
...
}
}