title: How do I use a Progress Bar with FtpWebRequest class?
body: <p>I was trying to do this on my own but have run into a situation where I need some help.  I would like to use a progressbar control to show the current progress of an FTP file upload.  </p>
  
  <p>Currently, I am manually changing the value of the progressbar control - but I couldn't help but think that there's probably a better or simpler approach out there.  It works right now, but the progressbar is sporadic in showing the progress based on the part of code which is being executed.  Also, I attempted to throw the entire sub into a separate thread, but noticed that when I did that the progressbar doesn't show until the end of the code - then it flashes briefly and hides again.</p>
  
  <p>Here's what I've done thus far, any help would be appreciated:</p>
  
  <pre><code>Public Sub uploadAuthorization()
  
      ProgressBar1.Show()
      Dim fileName As String = Path.GetFileName(TextBoxFilePath.Text)
      Dim ftpFolder As String = "authorizations"
  
      Try
          'Create FTP Request
          Me.Cursor = Cursors.WaitCursor
          Dim myRequest As FtpWebRequest = DirectCast(WebRequest.Create(ftpServer + "/" + ftpFolder + "/" + fileName), FtpWebRequest)
          ProgressBar1.Value = 20
  
          'Update properties
          myRequest.Credentials = New NetworkCredential(ftpUsername, ftpPassword)
          myRequest.Method = WebRequestMethods.Ftp.UploadFile
          ProgressBar1.Value = ProgressBar1.Value + 20
  
          'Read the file
          Dim myFile As Byte() = File.ReadAllBytes(TextBoxFilePath.Text)
          ProgressBar1.Value = ProgressBar1.Value + 20
  
          'Upload the file
          Dim myStream As Stream = myRequest.GetRequestStream()
          myStream.Write(myFile, 0, myFile.Length)
          ProgressBar1.Value = ProgressBar1.Value + 20
  
          'Cleanup
          myStream.Close()
          myStream.Dispose()
          ProgressBar1.Value = ProgressBar1.Value + 20
  
      Catch ex As Exception
          MsgBox(ex.Message, MsgBoxStyle.Information)
      End Try
      Me.Cursor = Cursors.Arrow
  End Sub
  </code></pre>