当前位置: 代码网 > it编程>编程语言>Asp.net > .NET Framework 的项目如何使用 FTP 下载文件

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

2024年05月15日 Asp.net 我要评论
免费ftp客户端 cyberduck for windows v8.7.1.4077 免费安装版ftp客户端工具 smartftp v10.0.3169 64bit 官方最新安装版ftp客户端工具 f

免费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","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();
        }
    }
}

到此这篇关于 .net framework 的项目如何使用 ftp 下载文件的文章就介绍到这了,更多相关ftp 服务器下载文件内容请搜索代码网以前的文章或继续浏览下面的相关文章希望大家以后多多支持代码网!

(0)

相关文章:

版权声明:本文内容由互联网用户贡献,该文观点仅代表作者本人。本站仅提供信息存储服务,不拥有所有权,不承担相关法律责任。 如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 2386932994@qq.com 举报,一经查实将立刻删除。

发表评论

验证码:
Copyright © 2017-2025  代码网 保留所有权利. 粤ICP备2024248653号
站长QQ:2386932994 | 联系邮箱:2386932994@qq.com