FtpWebRequest ftpRequest = (FtpWebRequest)WebRequest.Create(ConfigurationSettings.AppSettings["RemoteFileLocation"].ToString() + lblFolderName.Text); ftpRequest.Credentials = new NetworkCredential(ConfigurationSettings.AppSettings["UsrNm"].ToString(), ConfigurationSettings.AppSettings["Pwd"].ToString()); ftpRequest.Method = WebRequestMethods.Ftp.ListDirectory; FtpWebResponse response = (FtpWebResponse)ftpRequest.GetResponse(); StreamReader streamReader = new StreamReader(response.GetResponseStream()); string line = streamReader.ReadLine(); while (!string.IsNullOrEmpty(line)) { using (WebClient webClient = new WebClient()) { webClient.DownloadProgressChanged += new DownloadProgressChangedEventHandler(ProgressChanged); webClient.DownloadFileAsync(new Uri(string.Concat(ConfigurationSettings.AppSettings["RemoteFileLocation"].ToString(), lblFolderName.Text, "/", line)), string.Concat(savePath, "/", line)); webClient.DownloadFileCompleted += new AsyncCompletedEventHandler(Completed); btnDelete.Enabled = false; btnDownload.Enabled = false; button1.Enabled = false; } line = streamReader.ReadLine(); } streamReader.Close(); private void ProgressChanged(object sender, DownloadProgressChangedEventArgs e) { try { progressBar1.Value = e.ProgressPercentage; if (e.ProgressPercentage == 100) { aa = aa + 1; if (aa >= 1) { lblStatus.Text = (aa).ToString() + " Files Downloaded"; if (aa == count) { lblStatus.Text = "Downloading Complete"; } } } } catch (Exception ex) { MessageBox.Show(ex.Message); } } private void Completed(object sender, AsyncCompletedEventArgs e) { }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)