我需要通过C#代码执行SFTP进程。我正在使用Windows服务。以下是我正在使用的代码。Windows服务中的SFTP
WebCash.writeToFile(WebCash.outerbatchpath, command);
WebCash.writeToFile(WebCash.outerbatchpath, "exit");
ProcessStartInfo psi = new ProcessStartInfo("cmd.exe", "/c "+WebCash.outerbatchpath);
psi.RedirectStandardOutput = true;
psi.RedirectStandardInput = true;
psi.RedirectStandardError = true;
psi.UseShellExecute = false;
psi.CreateNoWindow = true;
psi.WindowStyle = ProcessWindowStyle.Hidden;
Process p = new Process();
p.StartInfo = psi;
p.Start();
p.WaitForExit();
psi = null;
WebCash.writeToFile(WebCash.GetErrorLog(), DateTime.Now.ToString() + "- Running SFTP end - " + p.ExitCode);
return p.ExitCode;
虽然试图调试上面的代码调试器不能够通过p.WaitforExit()
函数(即)服务没有p.WaitforExit()
之后执行。
我在我的外部运行下面的命令(SFTP)。
psftp -b D:\Source_Data\SFTP\innerbatch.bat -l username -i D:\privatekey.ppk @servername
内蒙古批次包含以下命令
put D:\Source_Data\SFTP\FileToTransfer.xml
我需要退出代码也得到了错误。请帮助。
我已经更新我的答案。 – 2014-10-07 07:38:45
将p.WaitForExit()更改为p.StandardOutput.ReadToEnd()不起作用。同样的结果:( – user3859666 2014-10-07 14:07:51
好的,比它很可能是由于某些提示,请参阅我的编辑 – 2014-10-07 15:33:44