编辑 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()
似乎都不起作用。
我能做什么?
最佳答案
不确定此线程中暗示的这种方法是否可行:
关于c# - ftp 进程不会关闭 (c#),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31024619/