private void DoQueue() { while (!stop) { if (queueList.Count > 0) { FTPQueue queue = queueList[0]; FileInfo fileInf = new FileInfo(queue.file); queue.total = fileInf.Length; currentQueue = queue; string file = String.Format("/ux0:/{0}", fileInf.Name); FileStream fs = fileInf.Open(FileMode.Open, FileAccess.Read, FileShare.ReadWrite); try { using (FtpClient conn = new FtpClient()) { conn.Host = ip; conn.Port = int.Parse(port); conn.Credentials = new NetworkCredential("anonymous", ""); using (Stream strm = conn.OpenWrite(file)) { try { int buffLength = 8192; byte[] buff = new byte[buffLength]; int contentLen; // Read from the file stream 2kb at a time contentLen = fs.Read(buff, 0, buffLength); error = null; // Till Stream content ends while (contentLen != 0) { // Write Content from the file stream to the FTP Upload Stream queue.uploaded += contentLen; strm.Write(buff, 0, contentLen); contentLen = fs.Read(buff, 0, buffLength); Thread.Sleep(1); } // Close the file stream and the Request Stream strm.Close(); fs.Close(); } finally { strm.Close(); fs.Close(); } conn.Disconnect(); } } queueList.RemoveAt(0); } catch (WebException ex) { error = ex.Message; } catch (Exception ex) { error = ex.Message; } finally { fs.Close(); } } Thread.Sleep(1000); } }
private void timer1_Tick(object sender, EventArgs e) { if (SplitQueue != null) { long total = GetDirectoryLength(VitaPackageHelper.Helper.current); string fileSize = String.Format(new FileSizeFormatProvider(), "{0:fs}", total); ftpStatus.Text = "Processing ... " + fileSize; return; } if (connectionType.SelectedIndex == 1) { toolStripStatusLabel1.Text = "FTP Service:"; if (manager != null) { if (manager.isWorking()) { if (manager.error != "" && manager.error != null) { ftpStatus.Text = manager.error; } else { if (manager.getQueueCount() > 0) { FTPQueue queue = manager.currentQueue; String text = ""; if (queue != null) { if (last_uploaded == 0) { last_uploaded = queue.uploaded; } long speed = queue.uploaded - last_uploaded; last_uploaded = queue.uploaded; String speed_text = String.Format(new FileSizeFormatProvider(), "{0:fs}/s", speed); double progress = (double)queue.uploaded / (double)queue.total * 100; uploadProgress.Value = (int)progress > 100 ? 100 : (int)progress; text = speed_text; if (queue.obj != null) { ListViewItem item = queue.obj as ListViewItem; if (item != null) { if (uploadProgress.Value == 100) { item.SubItems[5].Text = "Done"; } else { item.SubItems[5].Text = uploadProgress.Value + "%"; } } } } ftpStatus.Text = String.Format("{0} Queue {1}", manager.getQueueCount(), text); } else { ftpStatus.Text = "Idle"; } } } else { ftpStatus.Text = "Stop"; } } } else { toolStripStatusLabel1.Text = "USB Service:"; if (copyManager != null) { if (copyManager.isWorking()) { if (copyManager.error != "" && copyManager.error != null) { ftpStatus.Text = copyManager.error; } else { if (copyManager.getQueueCount() > 0) { CopyQueue queue = copyManager.currentQueue; String text = ""; if (queue != null) { if (last_uploaded == 0) { last_uploaded = queue.uploaded; } long speed = queue.uploaded - last_uploaded; last_uploaded = queue.uploaded; String speed_text = String.Format(new FileSizeFormatProvider(), "{0:fs}/s", speed); double progress = (double)queue.uploaded / (double)queue.total * 100; uploadProgress.Value = (int)progress > 100 ? 100 : (int)progress; text = speed_text; if (queue.obj != null) { ListViewItem item = queue.obj as ListViewItem; if (item != null) { if (uploadProgress.Value == 100) { item.SubItems[5].Text = "Done"; } else { item.SubItems[5].Text = uploadProgress.Value + "%"; } } } } ftpStatus.Text = String.Format("{0} Queue {1}", copyManager.getQueueCount(), text); } else { ftpStatus.Text = "Idle"; } } } else { ftpStatus.Text = "Stop"; } } } }