ftp进程获胜';t关闭(c#)

本文关键字:关闭 进程 获胜 ftp | 更新日期: 2023-09-27 17:59:28

编辑3:解决方案

第2版:myProcess.WaitForInputIdle();能帮上忙吗

编辑:我刚刚发现这些文件甚至没有下载。我只是放弃删除旧的。请帮助://

所以我用这个代码从ftp服务器下载一个文件:

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");
   }
}

它运行得很好,但最后我得到一个控制台输出,上面写着User (*server*:(none)): Password:之类的内容,我必须输入一些内容,这样我的程序才能继续。

然而,无论我输入什么,我都会得到回复:

User anonymous cannot log in.

有人知道我该怎么避免吗?

我也试着跳过它,但无论是sw.WriteLine(" ");还是p.Close()似乎都不起作用。

我能做什么?

ftp进程获胜';t关闭(c#)

不确定这种方法是否可行,如本线程中所暗示的:

为什么我无法通过代码获得ftp.exe的输出?