我想将文件从本地驱动器复制到网络路径。我知道如何通过使用 ssh ftp 库来实现这一点,即使用 sftp.put(@ local, remote) ,但我不知道如何使用“sudo”。如果我没有网络路径的写入权限,该怎么办。
虽然我可以使用以下代码从网络路径中删除文件:
string username = ConfigurationManager.AppSettings.Get("username");
string pass = ConfigurationManager.AppSettings.Get("password");
string filename;
filename = "standalone-full.xml";
string directory1;
directory1 = "apps/instances/express_13000/configuration";
// connecting to machine
SshExec ssh = new SshExec("machine", "user");
ssh.Password = "password";
ssh.Connect();
Console.WriteLine("Connection Established");
// removing files from server
string command_express = "echo" + "'" + pass + "'" + "| sudo -S -u wtsnqa " + "/" + directory1 + "/" + filename + "-exec rm";
string output1 = ssh.RunCommand(command_express);