ftp目录列表超时。大量的分部 [英] ftp directory listing timeout. Huge number of subdirs

查看:754
本文介绍了ftp目录列表超时。大量的分部的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当您需要获取FTP服务器上所有目录的列表时,有什么办法可以处理这种情况:目录数量如此之大以至于需要太长的时间才能得到它,并且操作因超时而失败?

Is there any way to deal with situation when you need to get list of all directories on a FTP server, where the number of directories is so big that it takes too long to get it and operation fails with timeout?

我想知道是否有一些库可以让你以某种方式做到这一点?

I wonder if there are some libraries that let you do that somehow?

推荐答案

尝试像这样

        FtpWebRequest ftpRequest = (FtpWebRequest)WebRequest.Create(uri);
        ftpRequest.Credentials = new NetworkCredential("anonymous","yourName@SomeDomain.com");//replace with your Creds
        ftpRequest.Method = WebRequestMethods.Ftp.ListDirectory;
        FtpWebResponse response = (FtpWebResponse)ftpRequest.GetResponse();
        StreamReader streamReader = new StreamReader(response.GetResponseStream());

        List<string> directories = new List<string>();

        string line = streamReader.ReadLine();
        while (!string.IsNullOrEmpty(line))
        {
            directories.Add(line);
            line = streamReader.ReadLine();
        }

        streamReader.Close();

        // also add some code that will Dispose of the StreamReader object
        // something like ((IDisposable)streanReader).Dispose();
        // Dispose of the List<string> as well 
           line = null;

这篇关于ftp目录列表超时。大量的分部的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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