I am using the code below to download files from a unix ftp server. I am having a problem with the portion of the code that updates the progress bar. The way it is currently working it takes the bytes transfered and uses that as the value to update the progress bar with. The problem with that is I can't guarantee the size of each file. I tried to set the Maximum value to 999999999, but the file size (18,319KB) is to small to cause the progress bar to update if the Maximum size is that big. So what I want to be able to do is take the bytes transfered (e.ByteCount) and divide that by the total file size (18,319KB for example) then multiple the answer by 100 to get a percentage. The problem is that I am not getting an accurate file size and when I use the formula to calculate the percentage I get the following error in Visual Basic:
Operator '\' is not defined for types 'Long' and 'System.Drawing.Size'.
Can anyone help point me in the right direction? Any help will be greatly appreciated.
Thanks
Public Class Form1
Inherits System.Windows.Forms.Form
Delegate Sub UpdateProgressBarDelegate(ByVal byteCount As Long)
Private Sub Connect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Connect.Click
Try
FtpConnection1.ServerAddress = (HRMS_Server.Text)
FtpConnection1.UserName = (HRMS_UserName.Text)
FtpConnection1.Password = (HRMS_Password.Text)
FtpConnection1.Connect()
Connect.Enabled = False
Catch ex As Exception
MsgBox("Please check your user name and/or password!", MsgBoxStyle.Critical, "Authentication Error!")
HRMS_UserName.Clear()
HRMS_Password.Clear()
Connect.Enabled = True
If FtpConnection1.IsConnected = True Then
FtpConnection1.Close()
End If
GoTo notconnected
End Try
' Change to Temp folder, download the users file and change the extension to .txt
Try
FtpConnection1.ChangeWorkingDirectory("/var/tmp")
Dim file As String = HRMS_UserName.Text
Dim file_1 As String = HRMS_UserName.Text & ".txt"
Dim dlpath As String = My.Settings.folderpath
[b]Dim Size As Int32 = FtpConnection1.GetSize(file)[/b]
FtpConnection1.RenameFile(file, file_1)
FtpConnection1.DownloadFile(dlpath + file_1, file_1)
FtpConnection1.DeleteFile(file_1)
FtpConnection1.Close()
HRMS_UserName.Clear()
HRMS_Password.Clear()
Connect.Enabled = True
' Close the connection
Catch ex As Exception
MsgBox("Please check your network connection and make" & vbNewLine & "sure you have saved your file to the L1 printer!", MsgBoxStyle.Critical, "Connection/File Error!")
FtpConnection1.DeleteOnFailure = True
Connect.Enabled = True
HRMS_UserName.Clear()
HRMS_Password.Clear()
If FtpConnection1.IsConnected = True Then
FtpConnection1.Close()
End If
End Try
notconnected:
End Sub
Private Sub FtpConnection1_BytesTransferred(ByVal sender As Object, ByVal e As EnterpriseDT.Net.Ftp.BytesTransferredEventArgs) Handles FtpConnection1.BytesTransferred
Dim arguments As Object
arguments = (e.ByteCount / Size) * 100
ProgressBar1.Invoke(New UpdateProgressBarDelegate(AddressOf UpdateProgressBar), arguments)
End Sub
Private Sub UpdateProgressBar(ByVal ByteCount As Long)
ProgressBar1.Value = ByteCount
End Sub