2014-04-17 26 views

回答

2

是的。

How to Download Files with FTP複製的示例。這個例子是一個控制檯應用程序,但我認爲你可以很容易地計算出如何將它適配到你的網站的結構。

你可能會考慮的一件事就是在網站上託管文件(如普通的HTTP),然後通過WebClient而不是FTP下載。

using System; 
using System.IO; 
using System.Net; 
using System.Text; 

namespace Examples.System.Net 
{ 
    public class WebRequestGetExample 
    { 
     public static void Main() 
     { 
      // Get the object used to communicate with the server. 
      FtpWebRequest request = (FtpWebRequest)WebRequest.Create("ftp://www.contoso.com/test.htm"); 
      request.Method = WebRequestMethods.Ftp.DownloadFile; 

      // This example assumes the FTP site uses anonymous logon. 
      request.Credentials = new NetworkCredential ("anonymous","[email protected]"); 

      FtpWebResponse response = (FtpWebResponse)request.GetResponse(); 

      Stream responseStream = response.GetResponseStream(); 
      StreamReader reader = new StreamReader(responseStream); 
      Console.WriteLine(reader.ReadToEnd()); 

      Console.WriteLine("Download Complete, status {0}", response.StatusDescription); 

      reader.Close(); 
      response.Close(); 
     } 
    } 
}