c# - 如何从 FTP 获取文件(使用 C#)?

标签 c# .net ftp

现在我知道如何将文件从一个目录复制到另一个目录了,这真的很简单。

但现在我需要对来自 FTP 服务器的文件执行相同的操作。你能给我一些例子如何在更改文件名的同时从 FTP 获取文件吗?

最佳答案

看看How to: Download Files with FTPdownloading all files in directory ftp and c#

 // 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 {0}", response.StatusDescription);

            reader.Close();
            reader.Dispose();
            response.Close();  

编辑 如果您想重命名 FTP 服务器上的文件,请查看此 Stackoverflow question

关于c# - 如何从 FTP 获取文件(使用 C#)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8636921/

相关文章:

c# - 将变量作为参数传递给 javascript 中的 Url.Action

c# - 通过指定属性的唯一性从 List<> 获取对象

php - 如何读取文件,如果文件或目录在 Windows 共享驱动器(映射驱动器)上可用,请使用 php

python - 如何从python中的.sec.gz类型的ftp服务器读取文件

c# - Visual Studio - 路径中的非法字符

c# - native C# pdf 阅读器

c# - .Net Rest Web 服务响应具有默认的数据协定命名空间而不是预期的命名空间

.net - 是否有适用于 Windows Phone 7 的 SIP 库?

c# - DataTable 内部结构和多线程使用

node.js - 使用Node访问另一台服务器中的FTP