while (fileQueue.Count > 0) { string fileName = fileQueue.Dequeue(); int getindex = fileName.LastIndexOf("/"); string getsubfile = fileName.Substring(getindex, fileName.Length - getindex); string filePath = localPath; string srnew = fileName.Replace("ftp://" + ftpServerIP + ftpPath, " "); FtpWebRequest reqFTP; FileStream outputStream; try { //reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri("ftp://" + ftpServerIP + ftpFolderName + fileName)); reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri(fileName)); reqFTP.Method = WebRequestMethods.Ftp.DownloadFile; reqFTP.UseBinary = true; reqFTP.Credentials = new NetworkCredential(ftpUserID, ftpPassword); FtpWebResponse response = (FtpWebResponse)reqFTP.GetResponse(); Stream ftpStream = response.GetResponseStream(); long cl = response.ContentLength; // this.Invoke(new MethodInvoker(delegate { dataGridView1.Rows[count].Cells[3].Value = cl; })); int bufferSize = 2048; int readCount; byte[] buffer = new byte[bufferSize]; //Random rand = new Random(); // byte nextByte; int folderindex = srnew.LastIndexOf("/"); string folderfile = srnew.Substring(0, folderindex); if (folderfile != string.Empty) { if (Directory.Exists(localPath +folderfile)) { } else { Directory.CreateDirectory(localPath + folderfile); //writetextDownAfter(localPath + sr.Trim() + "/" + strname.Trim()); } } readCount = ftpStream.Read(buffer, 0, bufferSize); int i = 1; while (File.Exists(filePath + srnew.Trim())) { string[] over = srnew.Split('.'); over[0] = over[0] + i.ToString(); srnew = over[0] + "." + over[1]; i++; } outputStream = new FileStream(filePath + srnew, FileMode.Create); //Stopwatch sw = new Stopwatch(); //sw.Start(); this.Invoke(new MethodInvoker(delegate { dataGridView1.Rows.Add("Server1", getsubfile.ToString(), "Downloading"); })); int count = dataGridView1.Rows.Count - 2; this.Invoke(new MethodInvoker(delegate { dataGridView1.FirstDisplayedScrollingRowIndex = dataGridView1.Rows.Count - 1; })); while (readCount > 0) { outputStream.Write(buffer, 0, readCount); if (ftpStream.CanSeek) { long lll = ftpStream.Position; } readCount = ftpStream.Read(buffer, 0, bufferSize); } ftpStream.Close(); //outputStream.Close(); response.Close(); //this.Invoke(new MethodInvoker(delegate { dataGridView1.Rows[count].Cells[0].Value="Server1";})); //this.Invoke(new MethodInvoker(delegate { dataGridView1.Rows[0].Cells[1].Value = getsubfile; })); this.Invoke(new MethodInvoker(delegate { dataGridView1.Rows[count].Cells[2].Value = "Downloaded"; })); this.Invoke(new MethodInvoker(delegate { dataGridView1.FirstDisplayedScrollingRowIndex = dataGridView1.Rows.Count - 1; })); //this.Invoke(new MethodInvoker(delegate { dataGridView1.Rows.Add("Server1", getsubfile.ToString(), "Downloaded"); })); } catch (WebException ex) { string errMsg = (ex.Message); fileQueue.Enqueue(fileName); //MessageBox.Show("webexe"+ex.Message.ToString()); } catch (Exception ex) { string errMsg = (ex.Message); MessageBox.Show("exe" + ex.Message.ToString()); }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)