Thanks Lukas! Using your example code I converted to VB.NET and added a small modification to give both percentage of complete plus the KB per second:
Private _bytesPerSecond As Long
Private _eventTime As Integer
Private percentComplete As String
Private lastReport As DateTime = DateTime.MinValue
Public Sub FtpTransferProgress(ByVal sender As Object, ByVal e As FtpTransferProgressEventArgs)
Console.ForegroundColor = ConsoleColor.Green
' wait for the next event if this is a final or first event
If (e.State = FtpTransferState.None OrElse e.BytesSinceLastEvent = 0) Then
Return
End If
' calculate time since the last event and update the event time
Dim time As Integer = Environment.TickCount
Dim timeSinceLastEvent As Integer
timeSinceLastEvent = time - _eventTime
_eventTime = time
If timeSinceLastEvent = 0 Then
' wait for the next event if we are currently too fast
' (happens at the beginning while data is still being cached by the local TCP/IP stack)
Return
End If
' calculate the speed of the last block
Dim bytesPerSecond As Long = e.BytesSinceLastEvent * 1000 / timeSinceLastEvent
If _bytesPerSecond = 0 Then
' if this is the first block, use the current speed
_bytesPerSecond = bytesPerSecond
Else
' otherwise use a kind of a simple moving average calculation to smooth the number slightly
_bytesPerSecond = (_bytesPerSecond * 15 + bytesPerSecond) / 16
End If
If (DateTime.Now.Subtract(lastReport).TotalSeconds) > 1 Then
percentComplete = String.Format("Percent complete: {0:00.0}% - ", e.BytesTransferred * 100 / _totalLength)
lastReport = DateTime.Now
End If
Dim kbPerSecond As String = String.Format("Transfer speed: {0:00.0} KB/s", _bytesPerSecond / 1024)
Console.Write(percentComplete + kbPerSecond + vbCr)
End Sub 'FtpTransferProgress
with these lines before starting file transfer:
' do this before each transfer
_totalLength = GetFileSize(localFile)
_bytesPerSecond = 0
_eventTime = Environment.TickCount
ftp.PutFile(localFile, remoteFile)
and since our upload transfer list comes from a database array I used this sub to determine the filesize of the localFile:
Private Function GetFileSize(ByVal MyFilePath As String) As Long
Dim MyFile As New FileInfo(MyFilePath)
Dim FileSize As Long = MyFile.Length
Return FileSize
End Function
Anyway, it gave me what I needed thanks to your help!