首页 新闻 赞助 找找看

ftp遍历无法区分文件夹或是文件!

1
悬赏园豆:50 [待解决问题]

网上人说 文件夹有<DIR>标识,但是我遍历没有啊!  求高手帮助

    private string[] GetFileList(string path, string WRMethods)//上面的代码示例了如何从ftp服务器上获得文件列表
    {
        string[] downloadFiles;

        StringBuilder result = new StringBuilder();
        List<string> strs = new List<string>();
        try
        {
            Connect(path);
            reqFTP.Method = WebRequestMethods.Ftp.ListDirectoryDetails;
            //reqFTP.Method = WebRequestMethods.Ftp.ListDirectory;
            
            WebResponse response = reqFTP.GetResponse();
            StreamReader reader = new StreamReader(response.GetResponseStream());//中文文件名

            string line = reader.ReadLine();
            while (line != null)
            {
                //if (line.Contains("<DIR>"))
                //{
                    result.Append(line);
                    result.Append("\n");
                    
                //}
                line = reader.ReadLine();
            }
            // to remove the trailing '\n' 

            result.Remove(result.ToString().LastIndexOf('\n'), 1);

            reader.Close();

            response.Close();

            return result.ToString().Split('\n');
        }

        catch (Exception ex)
        {
             System.Web.HttpContext.Current.Response.Write(ex.Message);

            downloadFiles = null;

            return downloadFiles;

        }

    }

 

动态格式化的主页 动态格式化 | 初学一级 | 园豆:22
提问于:2012-11-12 19:08
< >
分享
所有回答(1)
0

http://blog.csdn.net/tongyiyi/article/details/5709916看看这篇文章,或者把上面的代码考下来用用

az235 | 园豆:8483 (大侠五级) | 2012-11-12 23:34
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册