Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ftp process won't close (c#)

Tags:

c#

process

cmd

ftp

EDIT 3: The solution

EDIT 2: Could myProcess.WaitForInputIdle(); help?

EDIT: I just found out that the files weren't even downloaded. I just forgott to delete the old ones. Please help :/

so I use this code to download a file from an ftp server:

Process p = new Process();
ProcessStartInfo info = new ProcessStartInfo();
info.WindowStyle = ProcessWindowStyle.Hidden;
info.FileName = "ftp.exe";
info.RedirectStandardInput = true;
info.UseShellExecute = false;

p.StartInfo = info;
p.Start();

using (StreamWriter sw = p.StandardInput)
{
   if (sw.BaseStream.CanWrite)
   {
      sw.WriteLine("open " + folder.server);
      sw.WriteLine(folder.cred.user);
      sw.WriteLine(folder.cred.password);
      sw.WriteLine("get " + file);
      sw.WriteLine("close");
      sw.WriteLine("quit");
   }
}

It works perfectly fine, but at the end I get a console output saying something like User (*server*:(none)): Password: and I have to enter something so my program continues.

However, what ever I enter I get the response:

User anonymous cannot log in.

Does anybody know how I can avoid that?

I also tried skipping it, but nor sw.WriteLine(" "); neither p.Close() seem to work.

What can I do?

like image 729
000000000000000000000 Avatar asked Nov 18 '25 00:11

000000000000000000000


1 Answers

Not sure this approach is possible as hinted at in this thread:

Why I cannot get the output of ftp.exe by code?

like image 171
JustAspMe Avatar answered Nov 19 '25 13:11

JustAspMe