用vb.net获取ftp上传速度
我正在尝试使用vb.net获取ftp流的上载速度,但未成功 我不确定数学是否正确,我在谷歌上搜索了一段时间,试图找到上传的公式,我在一些代码示例中找到了它,但用于下载 这是我的密码:用vb.net获取ftp上传速度,vb.net,upload,ftp,transfer,ftpwebrequest,Vb.net,Upload,Ftp,Transfer,Ftpwebrequest,我正在尝试使用vb.net获取ftp流的上载速度,但未成功 我不确定数学是否正确,我在谷歌上搜索了一段时间,试图找到上传的公式,我在一些代码示例中找到了它,但用于下载 这是我的密码: Dim chunksize As Integer = 2048 Dim offset As Long = 0 Dim readBytes As Long = 0 Dim startTime As DateTime Dim endTime As DateTime While offset < buffer.
Dim chunksize As Integer = 2048
Dim offset As Long = 0
Dim readBytes As Long = 0
Dim startTime As DateTime
Dim endTime As DateTime
While offset < buffer.Length
readBytes = fileStream.Read(buffer, 0, chunksize)
requestStream.Write(buffer, 0, readBytes)
offset += readBytes
endTime = DateTime.Now
Dim duration = endTime - startTime
Dim inASec As Double = 1000 / duration.Milliseconds
startTime = DateTime.Now
RaiseEvent FileSpeed(Math.Round((64 * inASec) / 8, 2).ToString)
RaiseEvent FileProgress(offset, buffer.Length)
End While
Dim chunksize As Integer=2048
长=0时的尺寸偏移
Dim readBytes长度=0
暗淡的开始时间作为日期时间
Dim endTime作为日期时间
而偏移量<缓冲区长度
readBytes=fileStream.Read(缓冲区,0,chunksize)
写入(缓冲区,0,读取字节)
偏移量+=读取字节数
endTime=DateTime.Now
变暗持续时间=结束时间-开始时间
Dim inASec为双精度=1000/持续时间。毫秒
startTime=DateTime.Now
RaiseEvent文件速度(Math.Round((64*inASec)/8,2.ToString)
RaiseEvent文件进度(偏移量,buffer.Length)
结束时
我认为你的做法有点不正确。我认为,通过测量传输的总字节数,然后除以经过的总秒数,可以更好地计算总体速度
例如,大致如下:
Dim chunksize As Integer = 2048
Dim offset As Long = 0
Dim readBytes As Long = 0
Dim startTime As DateTime
Dim duration As Double
startTime = DateTime.Now
While offset < Buffer.Length
readBytes = fileStream.Read(Buffer, 0, chunksize)
requestStream.Write(Buffer, 0, readBytes)
offset += readBytes
duration = startTime.Subtract(Date.Now).TotalSeconds
' Avoid divide by 0 errors
If duration = 0 Then
duration = 1
End If
RaiseEvent FileSpeed(Math.Round(offset / duration, 2).ToString)
RaiseEvent FileProgress(offset, Buffer.Length)
End While
Dim chunksize As Integer=2048
长=0时的尺寸偏移
Dim readBytes长度=0
暗淡的开始时间作为日期时间
暗持续时间为双倍
startTime=DateTime.Now
而偏移量<缓冲区长度
readBytes=fileStream.Read(缓冲区,0,chunksize)
写入(缓冲区,0,读取字节)
偏移量+=读取字节数
持续时间=开始时间。减去(日期。现在)。总秒数
'避免被0除的错误
如果持续时间=0,则
持续时间=1
如果结束
RaiseEvent文件速度(Math.Round(偏移量/持续时间,2.ToString)
RaiseEvent文件进度(偏移量,Buffer.Length)
结束时
我认为你的做法有点不正确。我认为,通过测量传输的总字节数,然后除以经过的总秒数,可以更好地计算总体速度
例如,大致如下:
Dim chunksize As Integer = 2048
Dim offset As Long = 0
Dim readBytes As Long = 0
Dim startTime As DateTime
Dim duration As Double
startTime = DateTime.Now
While offset < Buffer.Length
readBytes = fileStream.Read(Buffer, 0, chunksize)
requestStream.Write(Buffer, 0, readBytes)
offset += readBytes
duration = startTime.Subtract(Date.Now).TotalSeconds
' Avoid divide by 0 errors
If duration = 0 Then
duration = 1
End If
RaiseEvent FileSpeed(Math.Round(offset / duration, 2).ToString)
RaiseEvent FileProgress(offset, Buffer.Length)
End While
Dim chunksize As Integer=2048
长=0时的尺寸偏移
Dim readBytes长度=0
暗淡的开始时间作为日期时间
暗持续时间为双倍
startTime=DateTime.Now
而偏移量<缓冲区长度
readBytes=fileStream.Read(缓冲区,0,chunksize)
写入(缓冲区,0,读取字节)
偏移量+=读取字节数
持续时间=开始时间。减去(日期。现在)。总秒数
'避免被0除的错误
如果持续时间=0,则
持续时间=1
如果结束
RaiseEvent文件速度(Math.Round(偏移量/持续时间,2.ToString)
RaiseEvent文件进度(偏移量,Buffer.Length)
结束时
非常感谢,正确的数学是math.Round((offset/1024)/duration,2)。ToString获取kbps。非常感谢,正确的数学是math.Round((offset/1024)/duration,2)。ToString获取kbps。