Solved

c# download files from ftp

Posted on 2013-02-02
2
646 Views
Last Modified: 2013-02-21
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
Comment
Question by:Varshini S
2 Comments
 
LVL 7

Accepted Solution

by:
tipsybroom earned 500 total points
Comment Utility
0
 

Author Comment

by:Varshini S
Comment Utility
ipsybroom -i need to check this in FTP folder not local drive
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Summary Displaying images in RichTextBox is a common requirement with limited solutions available. Pasting through clipboard or embedding into RTF content only support static images.  This article describes how to insert Windows control objects int…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now