unit uMain;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs,IdFTP;
type
TForm1 = class(TForm)
private
{ Private declarations }
function FtpUpLoad(aFtpIP: string; aFtpPort: Integer; aFtpUserName: string; aFtpPassword: string; aFtpDir: string; aSourceFile: string; aDestFile: string): Boolean;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$ R *.dfm}
function TForm1.FtpUpLoad(aFtpIP: string; aFtpPort: Integer; aFtpUserName:
string; aFtpPassword: string; aFtpDir: string; aSourceFile: string; aDestFile:
string): Boolean;
var
aIdFTP: TIdFTP;
begin
Result := False;
if not FileExists(aSourceFile) then Exit;
aIdFTP := TIdFTP.Create(nil);
try
with aIdFTP do
begin
if Connected then Disconnect; //重新连接
Username := aFtpUserName;
Password := aFTpPassword;
Host := aFtpIP;
Port := aFtpPort;
Connect;
ChangeDir(aFtpDir); //改变目录
try
if aDestFile <> '' then
begin
Delete(aDestFile);
end;
except
end;
Put(aSourceFile, aDestFile);
Disconnect;
Result := True;
end;
finally
aIdFTP.Free;
end;
end;
end.