c# - ftp 进程不会关闭 (c#)

标签 c# process cmd ftp

编辑 3:The solution

编辑 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() 似乎都不起作用。

我能做什么?

最佳答案

不确定此线程中暗示的这种方法是否可行:

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

关于c# - ftp 进程不会关闭 (c#),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31024619/

相关文章:

c# - (http) coreclr/dnxCore 中的 Web 请求提供程序?

c - 将进程置于前台

windows - 通过 cmd 中的命令删除目录,但在 bat 文件中不使用相同的命令

powershell - Silver Searcher - 如何忽略文件

c# - 这是如何运作的? LINQ to Entities 触发程序集加载?

c# - DateTime 的 MVC 模型绑定(bind)使用 GET 或 POST 是不同的

c# - MySQL - 键 "PRIMARY"的重复条目

java - 难道每个线程都不需要自己的 JVM 副本吗?

java - 终止从线程启动的 Java 进程

windows - cmd.exe 查找具有完整路径的文件和目录?