C# 删除Linux服务器上存在的文件
试图使用拥有所有特权的用户运行sudo命令,但我的代码中出现了问题 我正试图通过C#代码删除远程服务器上的文件。它表示:当前上下文中不存在名称“pass”: 我的代码:C# 删除Linux服务器上存在的文件,c#,C#,试图使用拥有所有特权的用户运行sudo命令,但我的代码中出现了问题 我正试图通过C#代码删除远程服务器上的文件。它表示:当前上下文中不存在名称“pass”: 我的代码: SshExec sshExec = new SshExec("sj1slm612", "karansha"); sshExec.Password = "pass"; sshExec.Connect(); //Removing config files f
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”
下一个代码使用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;
}
}
请熟悉编译器错误和运行时错误之间的区别。你修复它们的方式是不同的。
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;
}
}