Putty - Delete files dynamically using C#

后端 未结 3 1902
渐次进展
渐次进展 2021-01-27 04:55

I am working on a Windows app with C# as a programming langugage.

Requirement is

  1. to login to putty dynamically
  2. delete old files from specific loca
3条回答
  •  时光说笑
    2021-01-27 05:19

    I don't know if this helps, because I can't try it right know, but it could lead you to the right direction. Try something like this:

    string hostname = "hostname";
    string login = "login";
    string password = "password";
    ProcessStartInfo startInfo = new ProcessStartInfo();
    startInfo.UseShellExecute = false;
    startInfo.RedirectStandardInput = true;
    startInfo.FileName = @"C:\Putty\plink.exe";
    startInfo.Arguments = string.Format("{0}@{1} -pw {2}", login, hostname, password);
    
    Process p = new Process();
    p.StartInfo = startInfo;
    p.Start();
    
    p.StandardInput.WriteLine("cd /dir1/dir2/NewFolder");
    

    You should try 'plink', which is the command line version of Putty. With startInfo.RedirectStandardInput you specify, that the you can write to the stdin of the process with p.StandardInput.WriteLine(). This is also available for stdout, so you can read the output of the process.

提交回复
热议问题