程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> Delphi >> 利用Indy的TIdFtp控件實現FTP協議(3)

利用Indy的TIdFtp控件實現FTP協議(3)

編輯:Delphi

(5)實現下載

在下載之前,必須查看DirectoryListing.Items[sCurrFile].ItemType是否為文件,如返回為ditDirectory則代表當前文件名為目錄,不能下載,必須導向到文件才可。如為文件,則可以進行下載。在下載前,設定傳輸的類型為二進制文件,並且指定本地要保存的路徑。通過調用Get方法,實現文件的下載。下載過程較慢,可以考慮將其放到線程中實現。

過程說明:

procedure Get(const ASourceFile: string; ADest: TStream; AResume: Boolean); overload;
procedure Get(const ASourceFile: string; const ADestFile: string; const ACanOverwrite: boolean; AResume: Boolean); overload;

從遠程服務器上獲取文件。

屬性說明:

const ASourceFile: string

遠程服務器上的源文件名

const ADestFile: string

保存到客戶機上的文件名

const ACanOverwrite: boolean = false

重寫同名文件

AResume: Boolean = false

是否進行斷點續傳

示例代碼:

SaveDialog1.FileName := Name;
if SaveDialog1.Execute then begin
SetFunctionButtons(false);
IdFTP1.TransferType := ftBinary;
BytesToTransfer := IdFTP1.Size(Name);
if FileExists(Name) then begin
case MessageDlg('File aready exists. Do you want to resume the download Operation?',
mtConfirmation, mbYesNoCancel, 0) of
mrYes: begin
BytesToTransfer := BytesToTransfer - FileSizeByName(Name);
IdFTP1.Get(Name, SaveDialog1.FileName, false, true);
end;
mrNo: begin
IdFTP1.Get(Name, SaveDialog1.FileName, true);
end;
mrCancel: begin
exit;
end;
end;
end
else begin
IdFTP1.Get(Name, SaveDialog1.FileName, false);
end;

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved