2007/09/18 | 上传文件
类别(语言类学习笔记) | 评论(0) | 阅读(22) | 发表于 17:13

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.


2

评论Comments