这篇博客给大家补充一个方法,就是得到一个目录下的所有文件名称。在前端调用,大家写一个递归去遍历就可以了,我在这里就不在写了。具体ftp下载的方法在我的另一篇博客里有,需要的可以去看一下。

/// <summary>
/// 读取文件目录下所有的文件名称,包括文件夹名称
/// </summary>
/// <param name="ftpAdd">传过来的文件夹路径</param>
/// <returns>返回的文件或文件夹名称</returns>
public static string[] GetFtpFileList(string ftpAdd )
{ string url = FTPCONSTR + ftpAdd;
FtpWebRequest ftpRequest = (FtpWebRequest)WebRequest.Create(new Uri(url));
ftpRequest.UseBinary = true;
ftpRequest.Credentials = new NetworkCredential(FTPUSERNAME, FTPPASSWORD); if (ftpRequest != null)
{
StringBuilder fileListBuilder = new StringBuilder();
//ftpRequest.Method = WebRequestMethods.Ftp.ListDirectoryDetails;//该方法可以得到文件名称的详细资源,包括修改时间、类型等这些属性
ftpRequest.Method = WebRequestMethods.Ftp.ListDirectory;//只得到文件或文件夹的名称
try
{ WebResponse ftpResponse = ftpRequest.GetResponse();
StreamReader ftpFileListReader = new StreamReader(ftpResponse.GetResponseStream(), Encoding.Default); string line = ftpFileListReader.ReadLine();
while (line != null)
{
fileListBuilder.Append(line);
fileListBuilder.Append("@");//每个文件名称之间用@符号隔开,便于前端调用的时候解析
line = ftpFileListReader.ReadLine();
}
ftpFileListReader.Close();
ftpResponse.Close();
fileListBuilder.Remove(fileListBuilder.ToString().LastIndexOf("@"), );
return fileListBuilder.ToString().Split('@');//返回得到的数组
}
catch (Exception ex)
{
return null;
}
}
else
{
return null;
}
}

  FTP实现文件的下载功能请参考博客:http://www.cnblogs.com/zhenzaizai/p/7434669.html。

C# 使用ftp下载一个文件夹下的所有文件,包括子目录文件夹的更多相关文章

  1. c# 控制台应用程序批量修改文件夹下的后缀名(包括子文件夹)

    using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Tex ...

  2. .NET Core中复制源文件夹下的所有内容到新文件夹

    .NET Core中没有原生的复制文件夹方法,我们可以自己写个: 新建一个.NET Core控制台项目,示例代码如下: using System; using System.IO; namespace ...

  3. 为多个文件夹下的C源代码编写Makefile文件

    上一篇文章写了如何为在同一个文件夹下的C源代码,本篇文章为多个文件夹下的C源代码编写Makefile文件. 建立两个文件夹,分别为abs与src.其最终目录结构如下: 1 $ ls * 2 jun.c ...

  4. java基础 File与递归练习 使用文件过滤器筛选将指定文件夹下的小于200K的小文件获取并打印按层次打印(包括所有子文件夹的文件) 多层文件夹情况统计文件和文件夹的数量 统计已知类型的数量 未知类型的数量

    package com.swift.kuozhan; import java.io.File; import java.io.FileFilter; /*使用文件过滤器筛选将指定文件夹下的小于200K ...

  5. matlab遍历文件夹下所有图片和遍历所有子文件夹下图片

    做图像处理实验,经常需要遍历当前文件下所有图片.matlab当然很早就考虑了这个问题,库函数dir就是完成这个工作的.函数返回的是一个存放所有目录下文件信息的结构体,通过遍历结构体就可以达到访问所有文 ...

  6. gitignore 忽略某文件夹下 非某后缀名的文件

    忽略指定文件夹下的除某一文件之外的其他文件 parent_dir/!spec_file_name.html 忽略指定文件夹下的除某一类后缀名的文件 parent_dir/*[!*.html] 注意:若 ...

  7. AutoIT: 返回文件目录下所有的文件名,包括子文件

    _filelist("D:\Snagit 10") Func _filelist($searchdir) ;;;函数名(形参) $search = FileFindFirstFil ...

  8. PHP获取文件夹内所有文件包括子目录文件的名称或路径

    /* * new getFile($_dir[,$_emptyDir,$_fileType]); * @parma $_dir 是目录名称 * @parma $_emptyDir 是否获取空文件夹,选 ...

  9. QT QFtp使用实例 从FTP下载一个文件

    1. ftp://ftp.denx.de/pub/u-boot/lowboot-1.0.0.patch.gz  下载文件 FtpGet.h #ifndef FTPGET_H #define FTPGE ...

随机推荐

  1. css:多个div在同一行显示

    使用float:left,也可以使用display : inline-block,可以使多个div在同一行显示. 示例如下: <div class="search_row"& ...

  2. 信息: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path:

    问题信息详细: 信息: The APR based Apache Tomcat Native library which allows optimal performance in productio ...

  3. cdoj844-程序设计竞赛 (线段树的区间最大连续和)【线段树】

    http://acm.uestc.edu.cn/#/problem/show/844 程序设计竞赛 Time Limit: 3000/1000MS (Java/Others)     Memory L ...

  4. fieldOfView

    fieldOfView 属性 fieldOfView:Number 语言版本:  ActionScript 3.0 运行时版本:  Flash Player 10, AIR 1.5 为三维视野指定一个 ...

  5. Codeforces Beta Round #9 (Div. 2 Only)

    Codeforces Beta Round #9 (Div. 2 Only) http://codeforces.com/contest/9 A gcd水题 #include<bits/stdc ...

  6. DAO层注入HibernateTemplate的两种方式

    -------------------------siwuxie095                                         DAO 层注入 HibernateTemplat ...

  7. [leetcode]426. Convert Binary Search Tree to Sorted Doubly Linked List二叉搜索树转有序双向链表

    Convert a BST to a sorted circular doubly-linked list in-place. Think of the left and right pointers ...

  8. [leetcode]179. Largest Number最大数

    Given a list of non negative integers, arrange them such that they form the largest number. Input: [ ...

  9. Go开发之VScode安装

    1.找到官网 https://code.visualstudio.com/ 2根据自己机器环境下载 3.下载vscode地址,macos版本 https://vscode.cdn.azure.cn/s ...

  10. layui学习<一>

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name ...