次の C# コードを使用して Linux ボックスに接続し、そこにあるスクリプトを実行しています。
public static void linux_connect()
{
KeyboardInteractiveAuthenticationMethod kauth = new KeyboardInteractiveAuthenticationMethod(<username>);
PasswordAuthenticationMethod pauth = new PasswordAuthenticationMethod(<username>,<password>);
ConnectionInfo connectionInfo = new ConnectionInfo(<host ip>, 22, <username>, kauth, pauth);
using (var ssh = new SshClient(connectionInfo))
{
ssh.Connect();
string command = "tmp/Ftp.sh";
var cmd = ssh.CreateCommand(command);
Console.WriteLine(cmd.Result);
var asynch = cmd.BeginExecute(delegate(IAsyncResult ar)
{
}, null);
var reader = new StreamReader(cmd.OutputStream);
while (!asynch.IsCompleted)
{
var result = reader.ReadToEnd();
if (string.IsNullOrEmpty(result))
continue;
Console.Write(result);
}
cmd.EndExecute(asynch);
}
}
私の Ftp.sh スクリプトは次のとおりです。
#!/bin/bash
cd /apps/sample_folder
sudo -u (authorized_username) ftp (some_server)
cd コマンドは正常に実行されますが、制御が sudo コマンドに到達すると、コンソールでパスワードの入力を求められるはずですが、残念ながらそうではありません。アプリケーションコンソールでパスワードの入力を求められ、パスワードを入力して目的の場所にファイルをコピーできるように、これをインタラクティブにする方法を誰か教えてください。