3

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?

Community
  • 1
  • 1
000000000000000000000
  • 1,467
  • 1
  • 19
  • 38
  • 1
    Why not just use a `Net.FtpWebRequest` ? – Alex K. Jun 24 '15 at 10:56
  • Nope - because what I do here is a workaround for `Net.FtpWebRequest`. I do have to use the native Windows ftp-client..I know it's stupid. – 000000000000000000000 Jun 24 '15 at 10:57
  • 1
    Can't we help with the original problem, or suggest another framework that supports your needs? Processing an interactive application is not the way to go. – Caramiriel Jun 24 '15 at 11:03
  • Or invoke FTP.EXE with a commands file – Alex K. Jun 24 '15 at 11:07
  • Well..what I try is to backup an "old" ZyWall 2 plus and it won't let me use FtpWebRequest (500: unknown command/ 520: command not implemented). The maschines step-by-step tutorial want's me to do exactly what my code does right now. – 000000000000000000000 Jun 24 '15 at 11:12
  • Is there a way to do these steps literally with FtpWebRequest? – 000000000000000000000 Jun 24 '15 at 11:16
  • Yes if FTP.EXE can do it so can FtpWebRequest; https://msdn.microsoft.com/en-us/library/ms229711(v=vs.110).aspx - Try that; if it does not work edit this or the new question you just posted with the code & result. – Alex K. Jun 24 '15 at 12:28
  • Well...erm...This is exactly what I used before. For the two devices that responded with 500 or 520 I tried it with ftp.exe which works from. Saying that the command was either unknown or unimplemented. – 000000000000000000000 Jun 24 '15 at 12:37

1 Answers1

1

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

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

Community
  • 1
  • 1
JustAspMe
  • 418
  • 1
  • 4
  • 18
  • Went with this: http://stackoverflow.com/questions/31026522/use-ftp-exe-with-c-sharp/31044015#31044015 (yup - I know, I like to post multiple questions for the same problem! Trying to stop.) – 000000000000000000000 Jun 25 '15 at 07:38