private void Button1_Click(object sender, EventArgs e) { string uri = "ftp://172.17.13.127/"; string username = "username"; string password = "pwd"; var list = FtplistFile(uri,username,password); string path = @"D:\Example"; foreach (var item in list) { Ftpdownloadfile(Path.Combine(uri, item), Path.Combine(path,item),username,password); } MessageBox.Show("success"); } private List<string> FtplistFile(string url,string username,string password) //get file name form ftp folder { FtpWebRequest listRequest = (FtpWebRequest)WebRequest.Create(url); listRequest.Method = WebRequestMethods.Ftp.ListDirectoryDetails; listRequest.Credentials = new NetworkCredential(username, password); List<string> lines = new List<string>(); using (FtpWebResponse listResponse = (FtpWebResponse)listRequest.GetResponse()) using (Stream listStream = listResponse.GetResponseStream()) using (StreamReader listReader = new StreamReader(listStream)) { while (!listReader.EndOfStream) { lines.Add(listReader.ReadLine()); } } List<string> name = new List<string>(); foreach (var line in lines) { string[] tokens = line.Split(new[] { ' ' }, 9, StringSplitOptions.RemoveEmptyEntries); string n = tokens[3]; name.Add(n); } return name; } private void Ftpdownloadfile(string to_uri,string path,string username,string password) { FtpWebRequest request = (FtpWebRequest)WebRequest.Create(to_uri); request.Method = WebRequestMethods.Ftp.DownloadFile; request.Credentials = new NetworkCredential(username, password); using (FtpWebResponse response = (FtpWebResponse)request.GetResponse()) { using (Stream responseStream = response.GetResponseStream()) { using (FileStream fs = new FileStream(path, FileMode.Create)) { byte[] buffer = new byte[102400]; int read = 0; do { read = responseStream.Read(buffer, 0, buffer.Length); fs.Write(buffer, 0, read); fs.Flush(); } while (!(read == 0)); fs.Flush(); fs.Close(); } } } }