从FTP服务器下载完整文件夹及其文件 [英] Download complete folder with its files from FTP server

查看:87
本文介绍了从FTP服务器下载完整文件夹及其文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我想从ftp服务器下载一个完整的文件夹及其文件.

例如,有一个文件夹"hello",其中有3个文件和1个目录子文件夹",其中有一个文件.

Hi,
I want to download a complete folder with its files from ftp server.

For Example, there is a folder "hello" with 3 files and 1 directory "subfolder" which has one file in it.

推荐答案

1)请求文件列表和目标文件夹中的文件夹
2)分别下载每个文件.
3)对子文件夹重复1)和2).
1) Request a list of files and folders in the target folder
2) Download each file separately.
3) Repeat 1) and 2) for the subfolders.


Simon Bang完全正确.
无论如何,我使用以下递归方法(几乎相同)
(请记住,这只是示例代码,用于说明逻辑):
Simon Bang is totally right.
Anyway, I use the following recursive approach (which is pretty much the same)
(keep in mind that this is just sample code to illustrate the logic):
public void DownloadFtpFolder(string ftpFolderPath)
{
    FtpFolder fo = new FtpFolder(folderPath);
    foreach (FtpFile fi in fo.FtpFiles)
    {
        DownloadFtpFile(fi.FtpFilePath);
    }
    foreach (FtpFolder f in fo.FtpFolders)
    {
        DownloadFolder(f.FtpFolderpath);
    }
}
public void DownloadFtpFile(string ftpFilePath)
{
    // download the file here
}


您需要一个ftp库来下载实际文件并浏览文件夹,但是我希望这可以从理论上说明如何做到这一点.

欢呼
安迪


You need a ftp library for downloading the actual files and navigating the folders, but I hope this illustrates how this could be done theoratically.

cheers
Andy


这篇关于从FTP服务器下载完整文件夹及其文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆