免费FTP客户端 Cyberduck for Windows v8.7.1.4077 免费安装版
FTP客户端工具 SmartFTP v10.0.3169 64bit 官方最新安装版
FTP客户端工具 FTPRush V3.5.6 绿色多语版
此示例演示如何从 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","[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 {response.StatusDescription}"); reader.Close(); response.Close(); } } }
到此这篇关于 .NET Framework 的项目如何使用 FTP 下载文件的文章就介绍到这了,更多相关FTP 服务器下载文件内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!
您可能感兴趣的文章:
- 基于C#实现FTP下载文件
- C#开发windows服务实现自动从FTP服务器下载文件
本文由 华域联盟 原创撰写:华域联盟 » .NET Framework 的项目如何使用 FTP 下载文件
转载请保留出处和原文链接:https://www.cnhackhy.com/160026.htm