Solved

Download a  folder using ftp to my local machine in c#

Posted on 2009-06-30
2
694 Views
Last Modified: 2012-05-07
I am able to download single file from folder by giving name statically ,But i am looking for downloading all files in ftpserver folder(source) to local folder path( Destination).

i.e.. if ftp server folder have 3 xml files in it,i want to copy all 3 xml files to my local machine on button click with out giving name of the files..........

           
protected void btnDownloadFile_Click(object sender, System.EventArgs e) 

        {
 

            FtpWebRequest myFtpWebRequest;

            FtpWebResponse myFtpWebResponse;

            StreamWriter myStreamWriter;

            myFtpWebRequest = (FtpWebRequest)WebRequest.Create("ftp://XXXXXXXXXXX.com/connection.txt");

            myFtpWebRequest.Credentials = new NetworkCredential("username", "password");

            myFtpWebRequest.Method = WebRequestMethods.Ftp.DownloadFile;

            myFtpWebRequest.UseBinary = true;

            myFtpWebResponse = (FtpWebResponse)myFtpWebRequest.GetResponse();

            myStreamWriter = new StreamWriter(("C:\\test\\connection.txt"));

            myStreamWriter.Write((new StreamReader(myFtpWebResponse.GetResponseStream()).ReadToEnd()));

            myStreamWriter.Close();

            lblMsg .Text = myFtpWebResponse.StatusDescription;

            myFtpWebResponse.Close();
 

       }

Open in new window

0
Comment
Question by:computer12
2 Comments
 
LVL 39

Accepted Solution

by:
abel earned 500 total points
ID: 24746113
This post from Microsoft shows how you can list the directory contents. You can use that with the  code you already have to download all files in the driectory; http://msdn.microsoft.com/en-us/library/ms229716.aspx
0
 

Author Comment

by:computer12
ID: 24758373
Thanks Abel!
I am able to do this using the above link and some research. After getting the file list, I binded this list(file names) to a grid view and allowed the user to select a file name. I downloaded all the files that were selected using this filename.
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

706 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

19 Experts available now in Live!

Get 1:1 Help Now