000000000000000000000
000000000000000000000

Reputation: 1467

ftp process won't close (c#)

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?

Upvotes: 3

Views: 364

Answers (1)

JustAspMe
JustAspMe

Reputation: 418

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

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

Upvotes: 1

Related Questions