Link to home
Start Free TrialLog in
Avatar of Varshini S
Varshini S

asked on

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;


         





        }
ASKER CERTIFIED SOLUTION
Avatar of tipsybroom
tipsybroom
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Varshini S
Varshini S

ASKER

ipsybroom -i need to check this in FTP folder not local drive