现在我知道如何将文件从一个目录复制到另一个目录了,这真的很简单。
但现在我需要对来自 FTP 服务器的文件执行相同的操作。你能给我一些例子如何在更改文件名的同时从 FTP 获取文件吗?
最佳答案
看看How to: Download Files with FTP或 downloading 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/