0

尝试使用拥有所有权限的用户运行 sudo 命令,但我的代码有问题。

我正在尝试通过 C# 代码删除远程服务器上存在的文件。它说:名称'pass'在当前上下文中不存在。:

我的代码:

 SshExec sshExec = new SshExec("sj1slm612", "karansha");
            sshExec.Password = "pass";
            sshExec.Connect();

            //Removing config files from sj1slm612 server

            string remove_config_file_express = "echo " + "'" + pass + "'" + "| sudo -S -u wtsnqa rm " + "/apps/instances/express_13000/configuration/standalone-full.xml";
            string output_express = sshExec.RunCommand(remove_config_file_express);
 Console.WriteLine("All config files removed");
            Console.ReadLine();
4

2 回答 2

1

编译器确实是正确的。您引用了一个名为 pass 的变量,您可能打算将其作为字符串“pass”

 string remove_config_file_express = "echo " + "'" + pass + "'" + "| sudo -S -u wtsnqa rm " + "/apps/instances/express_13000/configuration/standalone-full.xml";
于 2013-08-14T16:11:30.660 回答
0

使用 tamir 库下一个代码。

    public static bool BorrarArchivo(string rutaRemota) 
    {


        try
        {
            SshExec comando = new SshExec(Servidor, Usuario);
            comando.Password = Password;

            comando.Connect();

            string paso = comando.RunCommand("rm " + rutaRemota);

            comando.Close();

            return true;
        }
        catch (Exception ex)
        {

            mErrorSFTP = ex.Message;
            return false;
        }

    } 
于 2015-11-10T17:38:46.573 回答