2015-06-24 34 views
3

編輯3:The solutionFTP進程將不會關閉(C#)

編輯2:莫非myProcess.WaitForInputIdle();幫助?

編輯:我只是發現文件甚至沒有下載。 我只是forgott刪除舊的。請幫助:/

所以我用這個代碼從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()似乎工作。

我該怎麼辦?

+1

爲什麼不直接使用'Net.FtpWebRequest'? –

+0

不 - 因爲我在這裏做的是'Net.FtpWebRequest'的解決方法。我必須使用本地Windows ftp客戶端。我知道這很愚蠢。 – 000000000000000000000

+1

我們不能幫助解決原始問題,或者建議另一個支持您需求的框架嗎?處理交互式應用程序不是要走的路。 – Caramiriel

回答