Topic "Problem in C#.Net with StandardInput.WriteLine"

Author Message
Neshfi

Guest


Hello,

I got a weird problem and something tells me its very easy, but I can`t lay my finger on it. The problem is that when I use the StandardInput.WriteLine function the process never exits. Example code:

Code:

// 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!");
}


If I execute it like this, then it will keep hanging on the WaitForExit function, but if I would comment all the StandardInput lines and uncomment the StartInfo.Arguments line, then it will work perfectly fine.

Sadly I am in a position in which calling a script is out of the question.
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24555
Location: Prague, Czechia
I do not see anything obviously wrong. Can you add /log command-line parameter and post the log file?
_________________
Martin Prikryl
Advertisements

You can post new topics in this forum






Search Site

What is WinSCP?

It is award-winning SFTP client, SCP client, FTPS client and FTP client integrated into one software program for file transfer to FTP server or secure SFTP server. [More]

And it's free!

Donate

About donations

$9   $19   $49   $99

About donations

Recommend

WinSCP Privacy Policy

WinSCP License