下载使用FTP和C#中的所有文件 [英] Downloading all files using FTP and C#
本文介绍了下载使用FTP和C#中的所有文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
什么是使用C#和FTP下载在远程目录下的所有文件并将其保存到本地目录的最佳方式是什么?
What is the best way to download all files in a remote directory using C# and FTP and save them to a local directory?
感谢。
推荐答案
使用C#的FtpWebRequest和FtpWebReponse,你可以用下面的递归(确保该文件夹弦终止'\')
Using C# FtpWebRequest and FtpWebReponse, you can use the following recursion (make sure the folder strings terminate in '\'):
public void GetAllDirectoriesAndFiles(string getFolder, string putFolder)
{
List<string> dirIitems = DirectoryListing(getFolder);
foreach (var item in dirIitems)
{
if ( item.Contains('.') )
{
GetFile(getFolder + item, putFolder + item);
}
else
{
var subDirPut = new DirectoryInfo(putFolder + "\\" + item);
subDirPut.Create();
GetAllDirectoriesAndFiles(getFolder + item + "\\", subDirPut.FullName + "\\");
}
}
}
的
item.Contains( '。')是一个有点原始,但已经工作了我的目的。发表评论,如果您需要的方法的一个例子:
The "item.Contains('.')" is a bit primitive, but has worked for my purposes. Post a comment if you need an example of the methods:
GetFile(string getFileAndPath, string putFileAndPath)
或
DirectoryListing(getFolder)
这篇关于下载使用FTP和C#中的所有文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文