📢 Webサイト閉鎖と移転のお知らせ
このWebサイトは2026年9月に閉鎖いたします。
新しい記事は移転先で追加しております。(旧サイトでは記事を追加しておりません)

68行目: 68行目:
       string secretKeyPath = Path.Combine(System.Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".ssh",  
       string secretKeyPath = Path.Combine(System.Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".ssh",  
                                           "secret_key.pem");
                                           "secret_key.pem");
      var authMethod = new PrivateKeyAuthenticationMethod("username", new PrivateKeyFile(secretKeyPath, "finger_print"));
   
   
       // パスワード認証の場合(平文)
       // 公開鍵にパスフレーズが存在する場合
       //var authMethod = new PasswordAuthenticationMethod("username", "password");
      var authMethod = new PrivateKeyAuthenticationMethod("<リモートPCのユーザ名>",
                                                          new PrivateKeyFile(secretKeyPath, "finger_print"));
      // 公開鍵にパスフレーズが無い場合
      //var authMethod = new PrivateKeyAuthenticationMethod("<リモートPCのユーザ名>",
                                                            new PrivateKeyFile(secretKeyPath));
      // パスワード認証の場合
       //var authMethod = new PasswordAuthenticationMethod("<リモートPCのユーザ名>",
                                                          "<リモートPCのユーザ名のパスワード>");
   
   
       // 接続情報のインスタンス生成
       // 接続情報のインスタンス生成
       var connectionInfo = new ConnectionInfo("IPまたはホスト名", 22, "username", authMethod);
       var connectionInfo = new ConnectionInfo("<リモートPCのIPアドレス または ホスト名>",
                                              <ポート番号>,
                                              "<リモートPCのユーザ名>",
                                              authMethod);
   
   
       using (var client = new SftpClient(connectionInfo))
       using (var client = new SftpClient(connectionInfo))
159行目: 170行目:
       var authMethod = new PrivateKeyAuthenticationMethod("username", new PrivateKeyFile(secretKeyPath, "finger_print"));
       var authMethod = new PrivateKeyAuthenticationMethod("username", new PrivateKeyFile(secretKeyPath, "finger_print"));
   
   
       // パスワード認証の場合(平文)
       // 公開鍵にパスフレーズが存在する場合
       //var authMethod = new PasswordAuthenticationMethod("<リモートPCのユーザ名>", "<リモートPCのユーザ名のパスワード>");
      var authMethod = new PrivateKeyAuthenticationMethod("<リモートPCのユーザ名>",
                                                          new PrivateKeyFile(secretKeyPath, "finger_print"));
      // 公開鍵にパスフレーズが無い場合
      //var authMethod = new PrivateKeyAuthenticationMethod("<リモートPCのユーザ名>",
                                                            new PrivateKeyFile(secretKeyPath));
      // パスワード認証の場合
       //var authMethod = new PasswordAuthenticationMethod("<リモートPCのユーザ名>",
                                                          "<リモートPCのユーザ名のパスワード>")
   
   
       // 接続情報のインスタンス生成
       // 接続情報のインスタンス生成