华域联盟 .Net .NET Framework 的项目如何使用 FTP 下载文件

.NET Framework 的项目如何使用 FTP 下载文件

免费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

本文来自网络,不代表华域联盟立场,转载请注明出处。

作者: sterben

发表回复

联系我们

联系我们

2551209778

在线咨询: QQ交谈

邮箱: [email protected]

工作时间:周一至周五,9:00-17:30,节假日休息

关注微信
微信扫一扫关注我们

微信扫一扫关注我们

关注微博
返回顶部