在C#中列出FTP子文件夹 [英] List FTP subfloder in C#

查看:65
本文介绍了在C#中列出FTP子文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有ftp路径ftp:\\ 10.23.XX.XX \ IN,在"IN"文件夹中,我还有十个文件夹,分别是ES,US,UK等,在C#中,我只想读取文件夹名称而不是里面的文件.你能让我知道怎么做吗.谢谢.

我还使用了许多其他网站,这些网站告诉我要使用GetResponseStream,但我无法找到正确的代码来获取getdiretries.

立即重播将非常有帮助.谢谢.

I have ftp path ftp:\\10.23.XX.XX\IN and inside that "IN" folder i have ten more folder, which are ES, US,UK etc. in C# i want to read the folder names only and not the files inside. Could you please let me know how to do that. Thank you.

also I have used many more sites where its telling me to go for GetResponseStream but i am not able to find correct code to getdiretries.

immediate replay will be very much helpfull. Thank you.

推荐答案

请参阅本文;

http://sharpertutorials.com/ultimate-guide-ftp/ [
See this article;

http://sharpertutorials.com/ultimate-guide-ftp/[^]

Basically the article tells you exactly how to iterate the directories.


感谢您对它的了解,
我在很多站点上都找到了解决方案,我可以说可能在某些地方有解决方案,但是问题出在我的FTP设置上.这允许我读取和删除文件,但现在允许我读取根文件夹中的子文件夹的名称.

我下面的相同代码工作正常,

Thanks for looking into it ,
I refered many sites for the solution ,I can say there might be solution at may places but the issue was with my FTP settings. which was allowing me to read and drop the file but now allowing me to read the names of subfolders inside the root foler.

my same below code worked fine,

class Program
    {
        static void Main(string[] args)
        {
            
            ftpissue1();
        }

        public static void ftpissue1()
        {
            List<string> result = new List<string>();
            WebResponse response = null;
            StreamReader reader = null;
            try
            {
                FtpWebRequest reqFTP;
                
                reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri("ftp://10.88.0.78/IN"));
                reqFTP.UseBinary = true;
                                
                reqFTP.Credentials = new NetworkCredential("ABC", "ABC");
                reqFTP.Method = WebRequestMethods.Ftp.ListDirectoryDetails;
                
                response = reqFTP.GetResponse();

                reader = new StreamReader(response.GetResponseStream());
                while (!reader.EndOfStream)
                {
                    result.Add(reader.ReadLine());
                }
                               
            }
            catch
            {
                if (reader != null)
                {
                    reader.Close();
                }
                if (response != null)
                {
                    response.Close();
                }
            }
        }
}
</string></string>



我可以说,非常有意思的是,ftp具有用于读取,重命名文件,删除,删除等的不同设置.



I could say , its very imp to note that ftp has different settings for reading, renaming file, delete, drop etc.


这篇关于在C#中列出FTP子文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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