Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2009-06-30
2
Medium Priority
?
708 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 39

Accepted Solution

by:
abel earned 1500 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

722 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