0

I have a method I call to upload a file (which was as it should).

       private void uploadFile()
    {

        try
        {
            richTextBox1.AppendText("\n\nStarting file upload");
            FtpWebRequest request = (FtpWebRequest)WebRequest.Create("ftp://ftpservername.com/test.htm");
            request.Credentials = new NetworkCredential("myusername", "mypassword");
            request.UsePassive = true;
            request.UseBinary = true;
            request.KeepAlive = true;
            request.Method = WebRequestMethods.Ftp.UploadFile;

            FtpWebResponse response = (FtpWebResponse)request.GetResponse();

            Stream responseStream = response.GetResponseStream();
            StreamReader reader = new StreamReader(responseStream);

            richTextBox1.AppendText(reader.ReadToEnd());

            richTextBox1.AppendText("\n\nUpload Complete");

            reader.Close();
            response.Close();
            request = null;
        }


        catch (Exception ex)
        {
            MessageBox.Show(ex.Message);
        }
    }

I also have a progress bar (labelled uploadProgress) which I would like to show how much it left to upload.

I have a download section also which does has a working link to a progress bar, the code is from this page

https://www.fluxbytes.com/csharp/how-to-download-a-file-in-c-progressbar-and-download-speed/

but I cannot see how to use

    progressBar.Value = e.ProgressPercentage;

       Show the percentage on our label.     labelPerc.Text = e.ProgressPercentage.ToString() + "%";       // Update the label with how much data have been downloaded so far and the total size of the file we are currently downloading     labelDownloaded.Text = string.Format("{0} MB's / {1} MB's",         (e.BytesReceived / 1024d / 1024d).ToString("0.00"),         (e.TotalBytesToReceive / 1024d / 1024d).ToString("0.00"));

into my existing Upload Method.

can someone help me please ?

Gerald Oakham
  • 173
  • 12

0 Answers0