本ページは広告が含まれています。気になる広告をクリック頂けますと、サーバ運営費になります(^^
SSH.NETって何?
SSH.NETは、並列処理用に最適化された.NET用のセキュアシェル(SSH-2)ライブラリ
同期方式と非同期方式の両方を使用したSSHコマンドの実行が可能で、コマンド実行終了ステータスやそのほかの情報を取得する事ができます。
nugetで簡単に取得できる
nuget: コード共有する仕組み

SSHを検索するとSSH.NETが見つかる
SSH.NET is a Secure Shell (SSH) library for .NET, optimized for parallelism and with broad framework support.

コード生成
とりあえずボタンを一つ生成する

そのボタンの中のコードはこんな感じ
この時、
using Renci.SshNet;
しておく
private void SSH_Click(object sender, EventArgs e)
{
var connectionInfo = new ConnectionInfo("sftp.foo.com",
"guest",
new PasswordAuthenticationMethod("guest", "pwd"),
new PrivateKeyAuthenticationMethod("rsa.key"));
using (var client = new SftpClient(connectionInfo))
{
client.Connect();
}
}
接続ボタンを押すと、サーバ側で、接続ログが確認できた
Jun 16 10:22:24 ssh-bullseye sshd[1317]: Accepted password for guest from 192.168.0.100 port 55783 ssh2
Jun 16 10:22:24 ssh-bullseye sshd[1317]: pam_unix(sshd:session): session opened for user guest(uid=1000) by (uid=0)
Jun 16 10:22:24 ssh-bullseye systemd-logind[397]: New session 36 of user guest.
Jun 16 10:22:24 ssh-bullseye sshd[1323]: Received disconnect from 192.168.0.100 port 55783:11: Connection terminated by the client.
Jun 16 10:22:24 ssh-bullseye sshd[1323]: Disconnected from user guest 192.168.0.100 port 55783
Jun 16 10:22:24 ssh-bullseye sshd[1317]: pam_unix(sshd:session): session closed for user guest
作成されたフォルダの中身
こんな感じでできてる。

実は、昔作成したアプリケーションは、このdllを流用して作成してた。nugetしてない。
古いDLLを削除してnuget
古いDLLは削除して、nugetで最新の安定板を取得する

これで、最新版の
Renci.SshNet
がインストールされた

無事に起動した。
最新サーバにアクセスしてみると接続できた!
Jun 16 10:34:58 ssh-bullseye sshd[1331]: Accepted password for DESKTOP-GT from 172.21.100.15 port 55876 ssh2
Jun 16 10:34:58 ssh-bullseye sshd[1331]: pam_unix(sshd:session): session opened for user DESKTOP-GT(uid=1385) by (uid=0)
Jun 16 10:34:58 ssh-bullseye systemd-logind[397]: New session 37 of user DESKTOP-GT.
Jun 16 10:34:58 ssh-bullseye systemd: pam_unix(systemd-user:session): session opened for user DESKTOP-GT(uid=1385) by (uid=0)