Click here to Skip to main content
15,900,461 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.
Posted
Comments
nikunjmochi 19-Sep-12 6:53am    
can you use third party controls to read ftp?

See this article;

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

Basically the article tells you exactly how to iterate the directories.
 
Share this answer
 
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>


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

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900