簡體   English   中英

刪除Linux服務器上存在的文件

[英]Remove file present on Linux server

嘗試與具有所有特權的用戶一起運行sudo命令,但是我的代碼中有問題。

我正在嘗試通過C#代碼刪除遠程服務器上存在的文件。 它說:名稱“通過”在當前上下文中不存在。

我的代碼:

 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();

編譯器確實是正確的。 您引用了一個稱為pass的變量,您可能希望將其作為字符串“ pass”

 string remove_config_file_express = "echo " + "'" + pass + "'" + "| sudo -S -u wtsnqa rm " + "/apps/instances/express_13000/configuration/standalone-full.xml";

使用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;
        }

    } 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM