資料が少ない。NuGetでSSH.NETと検索。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
using System; using System.Windows.Forms; using Renci.SshNet; namespace BlogBackup { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { var pkci = new PrivateKeyConnectionInfo("URL",22, "user", new PrivateKeyFile("key", "pass")); using (var ssh = new SshClient(pkci)) { ssh.Connect(); var cmd = ssh.CreateCommand("ls"); cmd.Execute(); ssh.Disconnect(); } using (var ftp = new SftpClient(pkci)) { ftp.Connect(); ftp.DownloadFile("/home/xxx/test.sql", System.IO.File.OpenWrite("test.sql")); ftp.Disconnect(); } } } } |