1string cmd = "pscp";
2string arguments = String.Format("-v -pw {0} \"{1}\" {2}@{3}:{4}",
3 _pwd,
4 activityReport.UploadFilename,
5 _uid,
6 _url,
7 _uploadDir
8);
9
10ProcessStartInfo psi = new ProcessStartInfo();
11psi.FileName = cmd;
12psi.Arguments = arguments;
13
14Logger.Debug(psi.FileName + " " + psi.Arguments);
15
16psi.RedirectStandardOutput = true;
17psi.RedirectStandardError = true;
18
19psi.WindowStyle = ProcessWindowStyle.Normal;
20psi.UseShellExecute = false;
21
22Process listFiles = Process.Start(psi);
23StreamReader myOutput = listFiles.StandardOutput;
24StreamReader myError = listFiles.StandardError;
25
26listFiles.WaitForExit(10 * 60 * 1000); // timeout when?
27
28if (listFiles.HasExited)
29{
30 // did it exit gracefully?
31 Logger.Debug(myOutput.ToString() + myError.ToString());
32 listFiles.Close();
33}
34else
35{
36 // or did it timeout and need to kill it.
37 listFiles.Kill();
38 listFiles.Close();
39 throw new Exception("Upload timed out. " + myOutput.ToString() + myError.ToString());
40}