idftp 的GET问题(100)

  • 主题发起人 主题发起人 枝上柳绵
  • 开始时间 开始时间

枝上柳绵

Unregistered / Unconfirmed
GUEST, unregistred user!
郁闷死了,搞了一天,竟然没有任何进展用idftp下载时运行到get代码时就没有任何响应了,关闭窗体时产生wsastartup失败的错误经测试,还有list函数时也有这个问题procedure TForm1.btn1Click(Sender: TObject);var i:Integer;Dir_List:TStringList;begin tryself.idftp2.Host :=ipself.idftp2.Port :=1234;self.idftp2.Username :=**;self.idftp2.Password :=**;idftp2.TransferType:=ftASCII; Self.idftp2.Connect(True,-1); Except On E:Exception do begin Exit; end; end; try if idftp2.Connected then begin Dir_List:=TStringList.Create; //创建字符串列表类 idftp2.ChangeDir('/'); idftp2.List(Dir_List,'',true);//此处出错,没有响应 idftp2.Get('ip.asp','d:/ip.asp',True,true);//此处出错,没有响应 end; Except On E:Exception do begin ShowMessage(e.Message ); end end;end;
 
你是不是在搞TIdFTP多线程FTP下载啊?
 
我也在做TIdFTP的多线程FTP下载,但是每个线程下载的文件并不是设定的大小,而是整个文件的大小,即:有两个线程就是下载两次文件。我在TIdFTP的OnWorkBegin里设置了当前线程传输的最大值,但仍然不起作用。网上说用TidFTP的SendCMD传输指令:按照其顺序为: TIdFTP1.sendCmd('rest 100/r/n'); //测试是否支持断点下载 TIdFTP1.sendCmd('SIZE '+frmModel.sFileName+'/r/n'); //文件大小 TIdFTP1.sendCmd('PASV/r/n'); //获得端口号 TIdFTP1.SendCmd('TYPE I'+'/r/n'); //定义二进制传输模式 TIdFTP1.SendCmd('rest '+inttostr(tstart)+'/r/n'); //下载的起始点 TIdFTP1.sendCmd('RETR '+frmModel.sFileName+'/r/n'); 但以上要求仍然不可以实现。恳请高手指点啊。
 
楼上的,我这段代码不是做多线程的,只是单线程这里有段多线程的代码,以前用过(现在不用了)你参考一下吧,也是高手写的Delphi 多线程FTP下载实现There are few good examples of TFTP servers, so I wrote this complete server as an example. If works like a Secure TFTP server, since it only allows uploads/downloads from a specific directory. The example assumes that you open a new project with a new form (Form1), and drop one TFTP Server and TFTP Client on the form, and two buttons. The source below can be copied as such. Enjoy. -----CUT-----CUT-----CUT-----CUT-----CUT-----CUT-----CUT----- unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, IdBaseComponent, IdComponent, IdUDPBase, IdUDPServer, IdTrivialFTPServer, StdCtrls, IdUDPClient, IdTrivialFTP; type TForm1 = class(TForm) IdTrivialFTPServer1: TIdTrivialFTPServer; IdTrivialFTP1: TIdTrivialFTP; Button1: TButton; Button2: TButton; procedure FormCreate(Sender: TObject); procedure IdTrivialFTPServer1ReadFile(Sender: TObject; var FileName: String; const PeerInfo: TPeerInfo; var GrantAccess: Boolean; var AStream: TStream; var FreeStreamOnComplete: Boolean); procedure IdTrivialFTPServer1TransferComplete(Sender: TObject; const Success: Boolean; const PeerInfo: TPeerInfo; AStream: TStream; const WriteOperation: Boolean); procedure IdTrivialFTPServer1WriteFile(Sender: TObject; var FileName: String; const PeerInfo: TPeerInfo; var GrantAccess: Boolean; var AStream: TStream; var FreeStreamOnComplete: Boolean); procedure Button1Click(Sender: TObject); procedure Button2Click(Sender: TObject); private { Private declarations } public { Public declarations } TFTPPath : String; end; var Form1: TForm1; implementation {$R *.dfm} procedure TForm1.FormCreate(Sender: TObject); begin IdTrivialFTPServer1.ThreadedEvent := True; IdTrivialFTPServer1.Active := True; { Set the path to where the files will be stored/retreived } TFTPPath :=IncludeTrailingPathDelimiter('C:/Temp'); end; procedure TForm1.IdTrivialFTPServer1ReadFile(Sender: TObject; var FileName: String; const PeerInfo: TPeerInfo; var GrantAccess: Boolean; var AStream: TStream; var FreeStreamOnComplete: Boolean); Var FS : TFileStream; begin FreeStreamOnComplete := True; Try { Convert UNIX style filenames to WINDOWS style } While Pos('/',Filename)<>0 do Filename[Pos('/',Filename)] := '/'; { Assure that the filename DOES NOT CONTAIN any path information } Filename := ExtractFileName( Filename ); { Check if file exists } If FileExists( TFTPPath+Filename ) then Begin { Open file in READ ONLY mode } FS := TFileStream.Create( TFTPPath+Filename, fmOpenRead OR fmShareDenyWrite ); { Assign stream to variable } AStream := FS; { Set parameters } GrantAccess := True; End Else Begin GrantAccess := False; End; Except{ On errors, deny access } GrantAccess := False; If Assigned(FS) then FreeAndNil( FS );End; end; procedure TForm1.IdTrivialFTPServer1WriteFile(Sender: TObject; var FileName: String; const PeerInfo: TPeerInfo; var GrantAccess: Boolean; var AStream: TStream; var FreeStreamOnComplete: Boolean); Var FS : TFileStream; begin Try { Convert UNIX style filenames to WINDOWS style } While Pos('/',Filename)<>0 do Filename[Pos('/',Filename)] := '/'; { Assure that the filename DOES NOT CONTAIN any path information } Filename := ExtractFileName( Filename ); { Open file in WRITE ONLY mode } FS := TFileStream.Create( TFTPPath+Filename, fmCreate OR fmShareExclusive ); { Copy all the data } AStream := FS; { Set parameters } FreeStreamOnComplete := True; GrantAccess := True; Except { On errors, deny access } GrantAccess := False; If Assigned(FS) then FreeAndNil( FS ); End; end; procedure TForm1.IdTrivialFTPServer1TransferComplete(Sender: TObject; const Success: Boolean; const PeerInfo: TPeerInfo; AStream: TStream; const WriteOperation: Boolean); begin // Success = TRUE if the read/write operation was successfull // WriteOperation = TRUE if the client SENT a file to the server Try { Close the FileStream } If Assigned(AStream) then FreeAndNil(AStream); Except End; end; // Example of how to DOWNLOAD a file from the server procedure TForm1.Button1Click(Sender: TObject); Var ST : TMemoryStream; begin ST := TMemoryStream.Create; IdTrivialFTP1.Get('testfile.dat',ST); If Assigned(ST) then begin ShowMessage('Filesize='+IntToStr(ST.Size)); FreeAndNil(ST); end; end; // Example of how to UPLOAD a file to the server procedure TForm1.Button2Click(Sender: TObject); Var ST : TMemoryStream; I : Integer; S : String; begin { Create stream } ST := TMemoryStream.Create; { Initialize data } S := 'This is a test file. It whould appear in the '+ 'TFTP Server''s upload directory.'+#13#10; { Store in stream } ST.Write( S[1], Length(S) ); ST.Position := 0; { Send Stream to TFTP Server } IdTrivialFTP1.Put(ST,'textfile.txt'); { Free Stream } If Assigned(ST) then FreeAndNil(ST); { Show a dialog } ShowMessage('Done!'); end; end.
 
网上查了一下,好像是indy 版本的问题,我用的是indy 9,好像 indy10.2.3才能解决这个问题,请问谁有indy10.2.3这个版本啊我在迅雷上下了好久没有成功谢谢,....
 
谢谢了,枝上柳绵。我看不懂啊,我用的TIdFTP控件。现在最大的问题就是不能从指定位置开始下载。
 
给你一个网址,http://www.indyproject.org/Sockets/Docs/index.html你自己去看看吧,上面很多版本。
 
枝上柳绵,你好,上面的这段代码是FTP Server的,我想要的是FTP Client的。顺便问下,你有没有Api函数实现多线程下载的呢。
 
后退
顶部