• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 658
  • Last Modified:

c# download files from ftp

I am creating a application in c# to download files from ftp and copy in my local computer.
If download folder contains directory i need create a same folder in my local computer and down load all the files from same folder.

i am using the following code for this. This is works fine when down folder does not contains any directory.  i do not know how to fetch the all directory name from ftp directory and create the same folder in my local drive. Please let me know how to achieve this ?



private void button2_Click(object sender, EventArgs e)
        {
         

            ftpDirectory = FtpServerName.ToString() + FtpPath.ToString();
            FtpWebRequest request = (FtpWebRequest)WebRequest.Create(ftpDirectory);
            request.Credentials = new NetworkCredential(FtpUserName.ToString(), FtpPassword.ToString());
            request.Method = WebRequestMethods.Ftp.ListDirectory;

            StreamReader streamReader = new StreamReader(request.GetResponse().GetResponseStream());

            string fileName = "";

            while (fileName != null)
            {
               
                fileName = streamReader.ReadLine();
                if (fileName != null)
                {
                    string downLoadStatus = Download(FtpServerName.ToString(),
                     FtpPath.ToString(), fileName, localPath,
                        FtpUserName.ToString(), FtpPassword.ToString());
                }
            }

            request = null;
            streamReader = null;


         





        }
0
Varshini S
Asked:
Varshini S
1 Solution
 
Varshini SAuthor Commented:
ipsybroom -i need to check this in FTP folder not local drive
0

Featured Post

Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

Tackle projects and never again get stuck behind a technical roadblock.
Join Now