免费FTP客户端 Cyberduck for Windows v8.7.1.4077 免费安装版
FTP客户端工具 SmartFTP v10.0.3169 64bit 官方最新安装版
此示例演示如何从 FTP 服务器下载文件。
本文专门针对面向 .NET Framework 的项目。 对于面向 .NET 6 及更高版本的项目,不再支持 FTP。
C#
using System; using System.IO; using System.Net; 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","janeDoe@contoso.com"); FtpWebResponse response = (FtpWebResponse)request.GetResponse(); Stream responseStream = response.GetResponseStream(); StreamReader reader = new StreamReader(responseStream); Console.WriteLine(reader.ReadToEnd()); Console.WriteLine($"Download Complete, status {response.StatusDescription}"); reader.Close(); response.Close(); } } }