FTP process will not be closed (C #)

EDIT 3: Solution

EDIT 2: Could it myProcess.WaitForInputIdle();

help?

EDIT: I only found out that the files are not even loaded. I just didn't want to delete the old ones. Please, help:/

so i use this code to download file from 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 fine, but at the end I get console output saying something like User (*server*:(none)): Password:

and I need to enter something in order for my program to continue.

However, whatever I type, I get the answer:

User anonymous cannot log in.

      

Does anyone know how I can avoid this?

I also tried skipping it, but neither sw.WriteLine(" ");

works p.Close()

.

What can I do?

+3


source to share


1 answer


Not sure if this approach is possible, as hinted in this thread:



Why can't I get ftp.exe output by code?

+1


source







All Articles