FTP进程不会关闭(C#) [英] ftp process won't close (c#)

查看:273
本文介绍了FTP进程不会关闭(C#)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

修改3:解决方案

EDIT 3: The solution

编辑2:莫非 myProcess.WaitForInputIdle(); 帮助

EDIT 2: Could myProcess.WaitForInputIdle(); help?

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

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

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?

我也尝试跳过它,但也不 sw.WriteLine(); 既不 p.Close()似乎工作。

I also tried skipping it, but nor sw.WriteLine(" "); neither p.Close() seem to work.

我该怎么办?

推荐答案

不当然,由于在这个线程暗示这种做法是可行的:

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

为什么我不能获得代码的Ftp.exe的输出?

这篇关于FTP进程不会关闭(C#)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆