Hi NG
I'm a bit new to programming c# and have a question regarding ftp by the
command prompt. As far as I can see it should be possible to start a process
and pipe command streams into it. But I cant make it work, it always stalls
when I try to read the output:
/// code 1
Process ftpProcess = new Process();
ftpProcess.Star tInfo.FileName = "cmd";
ftpProcess.Star tInfo.CreateNoW indow = true;
ftpProcess.Star tInfo.RedirectS tandardInput = true;
ftpProcess.Star tInfo.RedirectS tandardOutput = true;
ftpProcess.Star tInfo.UseShellE xecute = false;
ftpProcess.Star t();
string output = ftpProcess.Stan dardOutput.Read ToEnd();
string error = ftpProcess.Stan dardError.ReadT oEnd();
ftpProcess.Stan dardInput.Write Line("ftp localhost");
ftpProcess.Stan dardInput.Write Line();
output = ftpProcess.Stan dardOutput.Read ToEnd();
error = ftpProcess.Stan dardError.ReadT oEnd();
ftpProcess.Stan dardInput.Write Line("username" );
ftpProcess.Stan dardInput.Write Line();
//... further ftp action - but I never get this far....
output = ftpProcess.Stan dardOutput.Read ToEnd();
error = ftpProcess.Stan dardError.ReadT oEnd();
ftpProcess.Wait ForExit();
///////////
I also tried:
/// code2
char [] output = new char [1000];
string all = "";
Process ftpProcess = new Process();
ftpProcess.Star tInfo.FileName = "cmd";
ftpProcess.Star tInfo.CreateNoW indow = true;
ftpProcess.Star tInfo.RedirectS tandardInput = true;
ftpProcess.Star tInfo.RedirectS tandardOutput = true;
ftpProcess.Star tInfo.UseShellE xecute = false;
ftpProcess.Star t();
int i = ftpProcess.Stan dardOutput.Read (output, 0, 1000);
ftpProcess.Stan dardInput.Write Line("ftp localhost");
i = ftpProcess.Stan dardOutput.Read (output, i, 1000-i);
ftpProcess.Stan dardInput.Write Line("username" );
ftpProcess.Stan dardInput.Write Line("password" );
ftpProcess.Stan dardInput.Write Line("mkdir test");
ftpProcess.Stan dardInput.Write Line("ls");
ftpProcess.Stan dardInput.Write Line("bye");
all = ftpProcess.Stan dardOutput.Read ToEnd();
thanx
ps. And yes - I did connect manually by the command prompt so it should
work.
I'm a bit new to programming c# and have a question regarding ftp by the
command prompt. As far as I can see it should be possible to start a process
and pipe command streams into it. But I cant make it work, it always stalls
when I try to read the output:
/// code 1
Process ftpProcess = new Process();
ftpProcess.Star tInfo.FileName = "cmd";
ftpProcess.Star tInfo.CreateNoW indow = true;
ftpProcess.Star tInfo.RedirectS tandardInput = true;
ftpProcess.Star tInfo.RedirectS tandardOutput = true;
ftpProcess.Star tInfo.UseShellE xecute = false;
ftpProcess.Star t();
string output = ftpProcess.Stan dardOutput.Read ToEnd();
string error = ftpProcess.Stan dardError.ReadT oEnd();
ftpProcess.Stan dardInput.Write Line("ftp localhost");
ftpProcess.Stan dardInput.Write Line();
output = ftpProcess.Stan dardOutput.Read ToEnd();
error = ftpProcess.Stan dardError.ReadT oEnd();
ftpProcess.Stan dardInput.Write Line("username" );
ftpProcess.Stan dardInput.Write Line();
//... further ftp action - but I never get this far....
output = ftpProcess.Stan dardOutput.Read ToEnd();
error = ftpProcess.Stan dardError.ReadT oEnd();
ftpProcess.Wait ForExit();
///////////
I also tried:
/// code2
char [] output = new char [1000];
string all = "";
Process ftpProcess = new Process();
ftpProcess.Star tInfo.FileName = "cmd";
ftpProcess.Star tInfo.CreateNoW indow = true;
ftpProcess.Star tInfo.RedirectS tandardInput = true;
ftpProcess.Star tInfo.RedirectS tandardOutput = true;
ftpProcess.Star tInfo.UseShellE xecute = false;
ftpProcess.Star t();
int i = ftpProcess.Stan dardOutput.Read (output, 0, 1000);
ftpProcess.Stan dardInput.Write Line("ftp localhost");
i = ftpProcess.Stan dardOutput.Read (output, i, 1000-i);
ftpProcess.Stan dardInput.Write Line("username" );
ftpProcess.Stan dardInput.Write Line("password" );
ftpProcess.Stan dardInput.Write Line("mkdir test");
ftpProcess.Stan dardInput.Write Line("ls");
ftpProcess.Stan dardInput.Write Line("bye");
all = ftpProcess.Stan dardOutput.Read ToEnd();
thanx
ps. And yes - I did connect manually by the command prompt so it should
work.
Comment