Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 718
  • Last Modified:

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

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
computer12
Asked:
computer12
1 Solution
 
abelCommented:
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
 
computer12Author Commented:
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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

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