Re: Problem in C#.Net with StandardInput.WriteLine
I do not see anything obviously wrong. Can you add /log command-line parameter and post the log file?
// Run hidden WinSCP process
Process winscp = new Process();
winscp.StartInfo.FileName = "winscp.com";
//winscp.StartInfo.Arguments = "/script=testscript.txt ";
winscp.StartInfo.UseShellExecute = false;
winscp.StartInfo.RedirectStandardInput = true;
winscp.StartInfo.RedirectStandardOutput = false;
winscp.StartInfo.RedirectStandardError = false;
winscp.StartInfo.CreateNoWindow = true;
winscp.Start();
// Feed in the scripting commands
winscp.StandardInput.WriteLine("option batch abort");
winscp.StandardInput.WriteLine("option confirm off");
winscp.StandardInput.WriteLine("open sftp://user:password@srv.somedomain.com -hostkey=\"ssh-rsa xxxx xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx\"");
winscp.StandardInput.WriteLine("cd /sftp");
winscp.StandardInput.WriteLine("lcd C:\\test");
winscp.StandardInput.WriteLine("get test2.txt");
winscp.StandardInput.WriteLine("put -permissions=777 test1.txt");
winscp.StandardInput.WriteLine("exit");
winscp.StandardInput.Close();
winscp.WaitForExit();
// Success (0) or error?
if (winscp.ExitCode != 0)
{
Console.WriteLine("Error occured");
}
else
{
Console.WriteLine("Success!");
}