印地上传速度
从这段代码中,我如何返回上传速度?
procedure TForm1.Button1Click(Sender: TObject);
begin
ftp.Host := 'domain';
ftp.Username := 'username';
ftp.password := 'password';
ftp.Connect;
ftp.Put('random-filename.ext'); //This is where it should grab only the latest file
//label1.caption := 'Download Speed: %s';
ftp.Quit;
ftp.Disconnect;
end;
需要定时器吗?
谢谢。
From this code, how can I return the upload speed?
procedure TForm1.Button1Click(Sender: TObject);
begin
ftp.Host := 'domain';
ftp.Username := 'username';
ftp.password := 'password';
ftp.Connect;
ftp.Put('random-filename.ext'); //This is where it should grab only the latest file
//label1.caption := 'Download Speed: %s';
ftp.Quit;
ftp.Disconnect;
end;
Would a timer be necessary?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
假设您使用的是
TIdFTP
组件,则必须使用OnWork
、OnWorkBegin
和OnWorkEnd
事件来计算传输速度。Assuming you are using a
TIdFTP
component then you must use theOnWork
,OnWorkBegin
andOnWorkEnd
events to calculate the transfer rate.TIdFTP.OnWorkBegin
事件将告诉您将要发送多少字节,而TIdFTP.OnWork
事件将告诉您在此期间到目前为止已发送了多少字节。转移。根据各个OnWork
事件触发之间经过的时间以及每个事件之间传输的字节数的差异,您可以计算速度。The
TIdFTP.OnWorkBegin
event will tell you how many bytes are going to be sent, and theTIdFTP.OnWork
event will tell you how many bytes have been sent so far during the transfer. Based on how much time passes between individualOnWork
event firings and the difference in transferred bytes between each one, you can calculate the speed.不需要 TTimer 类,只需 Indy 组件 OnWorkBegin、OnWork 和 OnWorkEnd 事件。
您可以执行如下操作,但我建议您将 FTP 代码放入线程中,并使用 Synchronize 方法更新用户界面,以获得最佳性能。
No TTimer class is necessary, only Indy component OnWorkBegin, OnWork and OnWorkEnd events.
You can do like below but I recommend you to put FTP code in a thread and to update user interface with the Synchronize method for best performance.
对于计时器部分:
您可以使用内置函数和全局变量:
由于 Windows API 函数 GetTickCount 已经以毫秒为单位,这是计算经过时间的简单方法,但仅限于 Windows 2000+:
For the timer part:
You can use the built in functions and global variables:
Since the Windows API function GetTickCount is already in milliseconds, it's an easy way to calculate elapsed time, but only on Windows 2000+: