我正在使用Delphi XE 6和Indy10开发FTP服务器.问题是我需要限制下载速度(必须是可配置的Ex.1 KB/s,1 MB/s等)并且我不能使它工作.我知道像BitsPerSec等道具,但这只会影响协议数据交换,而不会影响与RETR命令的文件交换.我在IdFTPServer.pass中看到,并且Stream被转换为字符串并使用repeat/until循环发送(使用IOHandler.Write())但我需要某种形式的控制上传/下载过程并且能够限制速度所有传入客户端连接.请帮忙实现这一目标吗?
PD:抱歉我的英语不好.
我尝试使用以下代码为RETR命令实现CommandHandler:
procedure TForm1.IdFTPServer1CommandHandlers0Command(ASender: TIdCommand);
var
LContext : TIdFTPServerContext;
vStream: TFileStream;
path: String;
vX: Integer;
LEncoding: IIdTextEncoding;
begin
LEncoding := IndyTextEncoding_8Bit;
LContext := ASender.Context as TIdFTPServerContext;
path := 'D:\indy_in_depth.pdf';
try
vStream := TFileStream.Create(path, fmOpenRead);
//LContext.DataChannel.FtpOperation := ftpRetr;
//LContext.DataChannel.Data := VStream;
LContext.DataChannel.OKReply.SetReply(226, RSFTPDataConnClosed);
LContext.DataChannel.ErrorReply.SetReply(426, RSFTPDataConnClosedAbnormally);
ASender.Reply.SetReply(150, RSFTPDataConnToOpen);
ASender.SendReply;
Memo1.Lines.Add('Sending a file with: ' + IntToStr(vStream.Size) + ' bytes');
//Make control of speed here !
for vX := 1 to vStream.Size do
begin
vStream.Position := vX;
LContext.Connection.IOHandler.Write(vStream, …Run Code Online (Sandbox Code Playgroud)