Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 无法在linux box C上执行脚本#_C#_Linux_Ssh - Fatal编程技术网

C# 无法在linux box C上执行脚本#

C# 无法在linux box C上执行脚本#,c#,linux,ssh,C#,Linux,Ssh,我使用下面的C#代码连接到Linux设备并执行一个脚本 public static void linux_connect() { KeyboardInteractiveAuthenticationMethod kauth = new KeyboardInteractiveAuthenticationMethod(<username>); PasswordAuthenticationMethod pauth = new PasswordAuthenticati

我使用下面的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);

    }

}

cd命令执行成功,但当控件到达sudo命令时,应提示我在控制台上输入密码,但不幸的是,我没有。有人能告诉我如何使此交互,以便在我的应用程序控制台上提示我输入密码,然后我可以输入密码,然后将文件从复制到所需的位置

我不知道您的SSHClient如何工作,但我猜您正在尝试在命令完成时读取输出。但命令未完成,因为它需要密码。您需要在调用命令之后但在其执行结束之前以某种方式发送密码。我不知道您的SSHClient类是否可以在这种情况下通知您。阅读手册。
#!/bin/bash
cd /apps/sample_folder

sudo -u (authorized_username) ftp (some_server)