Advertisement
Guest User

Untitled

a guest
Mar 31st, 2020
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.98 KB | None | 0 0
  1. {
  2. var processInfo = new ProcessStartInfo
  3. {
  4.     FileName = "sftp",
  5.     Arguments = $"-P {port} {user}@{server}",
  6.     RedirectStandardOutput = true,
  7.     RedirectStandardInput = true,
  8.     RedirectStandardError = true,
  9.     StandardOutputEncoding = Encoding.UTF8,
  10.     StandardErrorEncoding = Encoding.UTF8
  11. };
  12. _process = Process.Start(processInfo);
  13. _writer = _process.StandardInput;
  14. _process.BeginOutputReadLine();
  15. _process.BeginErrorReadLine();
  16.  
  17. _process.OutputDataReceived += _process_OutputDataReceived;
  18. _process.ErrorDataReceived += _process_ErrorDataReceived;
  19.  
  20. _writer.WriteLine("ls");
  21. }
  22.  
  23. private void _process_OutputDataReceived(object sender, DataReceivedEventArgs e)
  24. {
  25.     if (string.IsNullOrWhiteSpace(e.Data))
  26.         return;
  27.  
  28.     Console.WriteLine($"Msg: '{e.Data}'");
  29. }
  30.  
  31. private void _process_ErrorDataReceived(object sender, DataReceivedEventArgs e)
  32. {
  33.     if (string.IsNullOrWhiteSpace(e.Data))
  34.         return;
  35.  
  36.     Console.WriteLine($"Error: '{e.Data}'");
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement